Re: [json-lib-user] How to escape curly braces in JSON
Brought to you by:
aalmiray
From: Arash A. <ara...@re...> - 2007-11-08 12:50:55
|
ok, I guess I was using a very old (0.9) version of the jason-lib. I'll try this new one (2.2-SNAPSHOT) thanks, arash Andres Almiray schrieb: > I tested against the current dev version (2.2-SNAPSHOT) that has > changed little from 2.1 and it runs fine. > May I know which version of the library are you using? > > Here is the testcase I ran (besides the string you provided) > > public void testFromObjectCurliesOnString() { > String json = "{'prop':'{value}'}"; > JSONObject jsonObject = JSONObject.fromObject( json ); > assertNotNull( jsonObject ); > assertEquals( 1, jsonObject.size() ); > assertEquals( "\"{value}\"", jsonObject.get( "prop" ) ); > > json = "{'prop':'{{value}}'}"; > jsonObject = JSONObject.fromObject( json ); > assertNotNull( jsonObject ); > assertEquals( 1, jsonObject.size() ); > assertEquals( "\"{{value}}\"", jsonObject.get( "prop" ) ); > > json = "{'prop':'{{{value}}}'}"; > jsonObject = JSONObject.fromObject( json ); > assertNotNull( jsonObject ); > assertEquals( 1, jsonObject.size() ); > assertEquals( "\"{{{value}}}\"", jsonObject.get( "prop" ) ); > } > > > Regards, > Andres > > ----- Original Message ---- > From: Arash Amiri <ara...@re...> > To: jso...@li... > Sent: Wednesday, November 7, 2007 9:32:01 AM > Subject: [json-lib-user] How to escape curly braces in JSON > > Hi > I have a (I guess simple) question: > > I have a JSONString in Java such as > > String jsonString = "{ 'fields': [ > {name: 'Firstname{{}}',value: '{{{Tom}}}',attributes: [],}, > {name: 'Lastname',value: 'Meier',attributes: [],}, > {name: 'Knows',value: 'Frec',attributes: [{ name: 'Since', value: > '2000' }],}, > {name: 'Knows',value: 'Kim',attributes: [{ name: 'Since', value: > '2003' }],}, > {name: 'Knows',value: 'Mark',attributes: [{ name: 'Since', value: > '2002' }, > { name: 'From', value: 'Reports' }]} > ]}" > > When I use JSONObject jsonForm = new JSONObject(jsonString); > > I get an Exception: > > net.sf.json.JSONException: Expected a ':' after a key at character 7 > of {{{Tom}}} > > I dont get this. The braces are inside quotes, there should not be a > problem, or??? > > please help > greetings, arash > > > ------------------------------------------------------------------------- > This SF.net <http://SF.net> email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > json-lib-user mailing list > jso...@li... > <mailto:jso...@li...> > https://lists.sourceforge.net/lists/listinfo/json-lib-user > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com |