Re: [json-lib-user] Strings with square brackets being interpreted as arrays
Brought to you by:
aalmiray
From: Pedro P. <ped...@we...> - 2010-06-01 16:14:16
|
Hey again, Ok, seems I have it about figured out. Turns out that there is an actual issue with the way the parser deals (or doesn't deal) with whitespace between the colon and the value, which lead to not noticing quotes that were not contiguous with the :. That bit I fixed in JSONObject.java (attached diff and test case). I included a test.json file that reproduces this issue. I simply read the file into a string and run JSONSerializer.toJSON() on it. The test file also highlights a second bug, that seems to me to be somewhat deep seated: at several points, json-lib guesses whether strings are literal strings or json-encoded strings; there's no use/mention differentiation. Namely, see what happens to the value for the nestedobject key. After the JSONObject patch, I could safely remove the maybeJSON() logic from AbstractJSON._processValue() (AbstractJSON.java.diff), and all of the test file was correctly parsed. This second patch breaks a number of test cases, but all of them share a common element: no distinction between setting a value as being the "{}" string versus the {} empty set (or similar). I assert that the correct behaviour from json.element(key, "{}") should be set the value for key as the "{}" string, rather than defaulting to shorthand for something akin to json.element(key, JSONSerializer.toJSON("{}")). Regards, Pedro Pinheiro |