Re: [json-lib-user] Strings with square brackets being interpreted as arrays
Brought to you by:
aalmiray
From: Christoffer D. B. <cd...@fl...> - 2010-05-31 17:58:22
|
Hi, I have had the exact same problem. I solved it by changing the following files: src/main/jdk15/net/sf/json/JSONObject.java: public Object putByRef( Object key, Object value ) { if( key == null ){ throw new IllegalArgumentException( "key is null." ); } verifyIsNull(); Object previous = properties.get( key ); if (value instanceof String || value instanceof JSONObject || value instanceof JSONArray || value instanceof Boolean || value instanceof Integer || value instanceof Double || value instanceof Long ) { properties.put(key, value); return previous; } else { return put(key,value); } } And src/main/jdk15/net/sf/json/JSONArray.java: public boolean addByRef( Object value ) { if (value instanceof String || value instanceof JSONObject || value instanceof JSONArray || value instanceof Boolean || value instanceof Integer || value instanceof Double || value instanceof Long ) { this.elements.add(value); return true; } return add( value, new JsonConfig() ); } And then I only use putByRef and addByRef in my program. The key thing in the add/putByRef methods are that when you add/put a String then you do *not* call the original put/add methods that try to interpret the String. Best regards, Christoffer Dam Bruun On 31-05-2010 18:09, Pedro Pinheiro wrote: > Hello all, > > I'm having an issue with json-lib 2.2.3 and 2.3, where strings that > contain exactly a json-style array are interpreted as arrays rather > than strings ("key":"[1,2,3]" are being interpreted as if the source > read "key": [1,2,3]). A space at the end of the string seems to short- > circuit this behaviour (i.e. "key":"[1,2,3]" is misinterpreted, but > "key":"[1,2,3] " isn't). This seems to be consistent (and I find the > same behaviour) with what Pedro Alves posted about a year ago in this > mailling list, where the same happens with strings shaped like > "function(){}". Is this supposed to be a feature I'm unaware of, or is > this simply a bizarre bug? Thanks for your attention. > > Regards, > > Pedro Pinheiro > > ------------------------------------------------------------------------------ > > _______________________________________________ > json-lib-user mailing list > jso...@li... > https://lists.sourceforge.net/lists/listinfo/json-lib-user > |