Monday, April 1, 2013

Re: Complex JSON and overlay types

Thanks. I try it, but I don't undestand how does it works... Do you have simple examples or tutorials?
 
I try to do it:
interface Person {
   Names getNames();
   String getStyle();
 }
 interface Names {
   // Other properties, as above
  String getProp1();
  String getProp2();
  String getProp3();
 }
 // Declare the factory type
 interface MyFactory extends AutoBeanFactory {
   AutoBean<Names> names();
   AutoBean<Person> person();
 }

public class HelloWorld implements IsWidget,EntryPoint {
 
 
  public Widget asWidget() {
   String url="data.json";
   RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
     //builder.setHeader("Access-Control-Allow-Origin", "*");
    
     try {
       Request response = builder.sendRequest(null, new RequestCallback() {
         public void onError(Request request, Throwable exception) {
           // Code omitted for clarity
         }
         public void onResponseReceived(Request request, Response response) {
           MyFactory factory = GWT.create(MyFactory.class);
          
          AutoBean<Person> bean = AutoBeanCodex.decode(factory, Person.class, response.getText());
          
          System.out.println("oui "+ bean.as().getNames());
          
         }
       });
     } catch (RequestException e) {
     }
  return null;
  
   }

@Override
public void onModuleLoad() {
 
 asWidget();
}
 
}
 
I get null. What do you think?
 
I'm still interested by a method with overlay type (=> Javascript), just to get "Jack" and "John" in  {"records": [{"names": {"John": ["50", "H", "US"], "Jack": ["50", "H", "US"]}, "style": "TR"}]}.
 
Le lundi 1 avril 2013 12:43:37 UTC-4, Stefan Ollinger a écrit :
Hi,
you could take a look at http://code.google.com/p/google-web-toolkit/wiki/AutoBean

Regards,
Stefan

On 29.03.2013 14:18, sebastie...@isen-lille.fr wrote:
Hi everybody,
 
I want to read this kind of JSON with GWT:
 

{"records": [{"names": {"John": ["50", "H", "US"], "Jack": ["50", "H", "US"]}, "style": "TR"}]}

I use overlay for that.

If I use that, I get "TR":

 public final native String getStyle()
     /*-{
         return this.records[0].style;
     }-*/;

So, it's work. Now I want to get John and the list 50,H,US. If I use that I get null:

public final native String getNames(String i)
     /*-{
         return this.records[0].names[i];
     }-*/;

For the same thing, I try to do that and I get no result: (json is the of my class which is extended by JavaScriptObject)

       public final native JsArray<json> getArray(String key) /*-{
        return this[key] ? this[key] : new Array();
    }-*/;

and

result.getArray("names").toString()

 

Have you any idea to do what I want?

Thank you in advance !

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment