Hi, Parse the Json with someting like:
JSONValue reply = JSONParser.parse(resp); Test test = (Test) reply.isObject().getJavaScriptObject(); and where you have to use the data : test.getCode(); test.getNetworks(); Test overlay is someting like: public class Testextends JavaScriptObject { protected Test() { } public final native int getCode() /*-{ return this.code; }-*/; public final native JsArray<String> getNetworks() /*-{ return this.networks; }-*/; } I'm not sure if you can use String on JsArray generic overlay bu i hope you get the idea. gerste ha escrito: > Hello, > > I have a question regarding overlay types, as I have the feeling I > misunderstood something. > > I'm returning a JSON encoded String from a php application in the > following format. > > { > "Code" : 0, > "Networks" : [ "net1" , "net2" , "net3 " ] > } > > I implemented a small class extending JavaScriptObject. Other classes > extend this class and call on these get methods through their final > non-native methods. > > public abstract class JavaScriptObjectOverlay extends JavaScriptObject > { > > protected JavaScriptObjectOverlay() {} > > public static final native <T extends JavaScriptObject> T fromJson > (String json) > /*-{ > return eval('(' + json + ')'); > }-*/; > > public static final native <T extends JavaScriptObject> JsArray<T> > fromJsonAsArray(String json) > /*-{ > return eval('(' + json + ')'); > }-*/; > > public final native String get(String key) > /*-{ > return "" + this[key]; > }-*/ > > public final native <T extends JavaScriptObject> JsArray<T> getArray( > String key) > /*-{ > return this[key] ? this[key] : new Array(); > }-*/; > > public final int getInt(String key) { > return Integer.parseInt(get(key)); > } > > } > > In my other class I call using the string of the response: > > JavaScriptObjectOverlay responseJson = JavaScriptObjectOverlay.fromJson > (response.getText()); > > When I try to do something like this now: > > int code = responseJson.getInt("Code"); > > this works fine, but if I call: > > JsArray<JavaScriptObject> a = this.getArray("Networks"); > JavaScriptObject a.get(i); > > I get the following exception: > > java.lang.ClassCastException: java.lang.String cannot be cast to > com.google.gwt.core.client.JavaScriptObject > > Now, when I debug my application and check the ClassName and so on, it > is shown that the objects are of type JavaScriptObject ... > If I inspect the value something like this is shown to me: > > net1,net2,net3 > > Which lets me suspect, that it is indeed a String. There seems to be > no way to cast this to String or vice versa, as String is no child of > JavaScriptObject. > > My question is, why is there a Java String next to the > JavaScriptObjects, which makes it unable for me to use it. > > To be honest: > If I call toString() on the JsArray and then use the split(",") method > I can get the result I want, but I don't believe that it is meant to > be this way and I fear that this behavior may break some day. > > I'm new to GWT, so could someone enlighten me what I overlooked or did > wrong? > Thank you in advance. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en -~----------~----~----~----~------~----~------~--~---