Closed GoogleCodeExporter closed 8 years ago
The output is:
{"firstName":"John","lastName":"Smith","age":25,"address":{"streetAddress":"21
2nd Street","city":"New
York","state":"NY","postalCode":"10021"},"phoneNumber":[{"type":"home","number":
"212 555-1234"},{"type":"fax","number":"646 555-4567"}]}
Is that right? Isn't it the expected one?
Original comment by fangyid...@gmail.com
on 29 Nov 2011 at 3:15
Hi,
what I was asking is the difference between:
System.out.println(JSONValue.toJSONString(userMap));
and
System.out.println(new JSONObject(userMap));
In the former the order is preserved but in the latter is not.
To test this behaviour switch the former line with the latter one in
Wikipedia.java at line 78.
Thanks for your attention
Bye
Piero
Original comment by ottu...@gmail.com
on 29 Nov 2011 at 2:58
Yes. The order is determined by the implementation of the map iterator. For
JSONObject, it inherits java.util.HashMap and the order of its entry iterator
is not guaranteed even it accepts an ordered one in its constructor, that's why
the output is not ordered.
Original comment by fangyid...@gmail.com
on 30 Nov 2011 at 2:18
Original issue reported on code.google.com by
ottu...@gmail.com
on 29 Aug 2011 at 3:49Attachments: