Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#109 Data in array could be parsed when shouldn't

open
nobody
None
5
2010-09-24
2010-09-24
Anonymous
No

Example, same objects, parsed differently when in array and by self:

String test = "{\"c\":\"{\\\"k\\\":\\\"k\\\", \\\"l\\\":\\\"l\\\"}\"}";
JSONObject jsonObject = JSONObject.fromObject(test);
System.out.println("test = " + test);
System.out.println("json = " + jsonObject);

String test2 = "{\"a\":[{\"c\":\"{\\\"k\\\":\\\"k\\\", \\\"l\\\":\\\"l\\\"}\"}]}";
jsonObject = JSONObject.fromObject(test2);
System.out.println("test = " + test2);
System.out.println("json = " + jsonObject);

Produces:
test = {"c":"{\"k\":\"k\", \"l\":\"l\"}"}
json = {"c":"{\"k\":\"k\", \"l\":\"l\"}"}
test = {"a":[{"c":"{\"k\":\"k\", \"l\":\"l\"}"}]}
json = {"a":[{"c":{"k":"k","l":"l"}}]}

You can see that in case2 String was parsed to object by mistake

Discussion