Tuesday, March 26, 2013

Re: JSONParser.parseStrict() with \"



On Monday, March 25, 2013 9:39:57 PM UTC+1, rkulisas wrote:
For my case, I want to keep \". So I'd need to do 

replaceAll("\"","\\\"")

on all my java object toString() when I want to convert this back to JSON format. Is there a better GWT library to do this conversion? 

This is now I convert back to JSON string: 

public String toString(){

    return "{" + 

    "\"name\":" + ((name == null)? "null" : ("\"" + name + "\"")) +

    ", \"index\":" + index +

    ", \"text\":" + ((text == null)? "null" : ("\"" + text + "\"")) +

    "}";

    }


You need much more than replacing " with \" for your JSON to be valid, and yes that escaping has to be done within your toString() method.
Use JsonUtils.escapeValue(name) to have it as a quoted JSON string.

--
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