Menu

#84 Inconsistent decoding of function-like strings

open
nobody
None
5
2009-06-21
2009-06-21
Anonymous
No

json-lib inconsistently decodes function-like strings:

JSONObject.fromObject("{\"foo\":\"function() {return 0;}\"}")
-> {"foo":"\"function() {return 0;}\""}
and
JSONObject.fromObject("{\"foo\": \"function() {return 0;}\"}")
-> {"foo":function(){ return 0; }}

In the first instance, there are extra quotes in the resulting string.
In the second, which differs by having a space after the colon, the string has been treated as a function.

As it happens, I just want the value to remain a normal string -- i.e., neither of those -- but JSONObject.getString() does give me what I want in the second case. The trouble is that I don't control whether there is a space after the colon or not.

Discussion


Log in to post a comment.