Wednesday, August 3, 2011

Converting raw JSON to a JSONObject / JSONValue

The JSONObject takes only JavaScriptObject as its constructor parameter. JavaScriptObject can be returned only by a JSNI function which I wrote:

    public static native JavaScriptObject parseJson(String jsonStr) /*-{
        return eval(jsonStr);
    }-*/;

but when I do 

String json = "{\"userId\" : \"123\", \"sessionId\" : \"456\"}";
JavaScriptObject javaScriptObject = parseJson(json);


I get

ERROR: Uncaught exception escaped. com.google.gwt.core.client.JavaScriptException: (SyntaxError): Unexpected token : 

-Alex

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/Z8Uk3YifLLYJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment