On Tuesday, September 6, 2011 10:18:51 AM UTC+2, Konstantin Zolotarev wrote:
>
> I'm trying to get JavaScriptObject from JSON String 
>
> String looks like : 
> {"id":"1","username":"admin","token":"dq77a4uslui7neqcvidajofrg0"}
>
> I'm doing this via JSINI :
>
> public final native JavaScriptObject userFromJson(String json) /*-{ return 
> eval(json); }-*/;
>

Do not use eval(), unless you're absolutely sure of the origin of your JSON 
string (and even then –because you actually cannot be absolutely sure–, a 
quick sanity-check is always welcome).

GWT gives you tools for JSON parsing: use 
them! 
http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/core/client/JsonUtils.html
 

> And get this error :
>
>
> 14:18:24.740 [ERROR] [webpovise] Uncaught exception escaped
>
> com.google.gwt.event.shared.UmbrellaException: Exception caught: 
> (SyntaxError): Unexpected token :
>

That's because the "{" is seen as opening a block of code, so it later 
chokes on the ":" which is not legal in an expression context.

-- 
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/-/dI75zmMPQx0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to