Monday, March 25, 2013

Re: JSONParser.parseStrict() with \"

Hi Thomas,

I don't have control over the string value that gets passed in to me. If I don't get \" in return, the JSON will be invalid. I'm having similar problem to this thread.

Thank you

On Monday, March 25, 2013 3:57:19 AM UTC-7, Thomas Broyer wrote:

On Monday, March 25, 2013 11:23:51 AM UTC+1, rkulisas wrote:

//josn is {"name":"item_name","index":0,"text":"Kindle Fire HD 8.9\"..."}

JSONValue value = JSONParser.parseStrict(json);

JSONObject obj;

JSONString name, text;

JSONNumber nxd;

if ((obj = value.isObject()) == null ) return null;

if ((value = obj.get("name")) != null) 

if ((name = value.isString()) != null)


if ((value = obj.get("text")) != null) 

if ((text = value.isString()) != null){

System.out.println("VALUE:" + value.toString());  //VALUE:"Kindle Fire HD 8.9\" ..."

System.out.println("TEXT:" + text.stringValue()); //TEXT:Kindle Fire HD 8.9" ...



Am I supposed to use JSONValue.toString() to get my string value instead? Why JSONString.stringValue() doesn't parse properly?

The question is more: why do you want the \ to be there?
It's in your JSON because JSON uses " to markup string literals and thus has to escape " that appears within the string value, just like you do in Java or JavaScript or so many other languages (C, etc.)

stringValue() *does* return the correct value, it's just that you're expecting something else.

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
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment