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+unsubscr...@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.
Re: JSONParser.parseStrict() with \"
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 + "\"")) + "}"; } On Monday, March 25, 2013 1:23:43 PM UTC-7, rkulisas wrote: > > 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. > http://stackoverflow.com/questions/13420115/padding-quotes-in-jsonobject > > 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) >>> >>>field.setName(name.stringValue()); >>> >>> 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" ... >>> >>> field.setText(text.stringValue()); >>> >>> } >>> 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 google-web-toolkit+unsubscr...@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.
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. http://stackoverflow.com/questions/13420115/padding-quotes-in-jsonobject 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) >> >>field.setName(name.stringValue()); >> >> 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" ... >> >> field.setText(text.stringValue()); >> >> } >> 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 google-web-toolkit+unsubscr...@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.
Re: JSONParser.parseStrict() with \"
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) > >field.setName(name.stringValue()); > > 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" ... > > field.setText(text.stringValue()); > > } > 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 google-web-toolkit+unsubscr...@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.
Re: JSONParser.parseStrict() with \"
//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) field.setName(name.stringValue()); 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" ... field.setText(text.stringValue()); } Am I supposed to use JSONValue.toString() to get my string value instead? Why JSONString.stringValue() doesn't parse properly? Thank you On Monday, March 25, 2013 2:04:45 AM UTC-7, Thomas Broyer wrote: > > > > On Monday, March 25, 2013 3:13:53 AM UTC+1, rkulisas wrote: >> >> Before calling parseStrict(): >> {"name":"item_name","index":0,*"text":"Kindle Fire HD 8.9\"..."*} >> > > So the "text" property of the object is the string « Kindle Fire HD > 8.9"... » > > >> After parseStrict(): >> {"name":"item_name", "index":0, *"text":"Kindle Fire HD 8.9" ..."*} >> > > JsonUtils gives you an object, not a JSON string, so the above line > doesn't mean much things. > -- 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+unsubscr...@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.
Re: JSONParser.parseStrict() with \"
On Monday, March 25, 2013 3:13:53 AM UTC+1, rkulisas wrote: > > Before calling parseStrict(): > {"name":"item_name","index":0,*"text":"Kindle Fire HD 8.9\"..."*} > So the "text" property of the object is the string « Kindle Fire HD 8.9"... » > After parseStrict(): > {"name":"item_name", "index":0, *"text":"Kindle Fire HD 8.9" ..."*} > JsonUtils gives you an object, not a JSON string, so the above line doesn't mean much things. -- 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+unsubscr...@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.
Re: JSONParser.parseStrict() with \"
Before calling parseStrict(): {"name":"item_name","index":0,*"text":"Kindle Fire HD 8.9\"..."*} After parseStrict(): {"name":"item_name", "index":0, *"text":"Kindle Fire HD 8.9" ..."*} On Sunday, March 24, 2013 3:14:50 AM UTC-7, Thomas Broyer wrote: > > Could you show your code? (JSON string I mean) > > On Sunday, March 24, 2013 9:14:18 AM UTC+1, rkulisas wrote: >> >> Hi, >> >> I have JSON string that contains \". When I pass this to either >> parseStrict() or parseLenient(), I get back string with " instead of \". I >> tested this with JS eval() as well. eval() returns string with \". Anyone >> know how to work around this? >> >> Thank you. >> > -- 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+unsubscr...@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.
Re: JSONParser.parseStrict() with \"
Could you show your code? (JSON string I mean) On Sunday, March 24, 2013 9:14:18 AM UTC+1, rkulisas wrote: > > Hi, > > I have JSON string that contains \". When I pass this to either > parseStrict() or parseLenient(), I get back string with " instead of \". I > tested this with JS eval() as well. eval() returns string with \". Anyone > know how to work around this? > > Thank you. > -- 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+unsubscr...@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.
JSONParser.parseStrict() with \"
Hi, I have JSON string that contains \". When I pass this to either parseStrict() or parseLenient(), I get back string with " instead of \". I tested this with JS eval() as well. eval() returns string with \". Anyone know how to work around this? Thank you. -- 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+unsubscr...@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.