Reputation: 19288
I was parsing a string to a JSONObject and noticed some weird behaviour. The orders of items get scrambled? Is this a bug or did i do something wrong?
Upvotes: 0
Views: 67
Reputation: 22038
Your 'items' are key/value pairs in a JSON object. The order of key/value pairs within a JSON object is not guaranteed:
An object is an unordered set of name/value pairs.
If you need to preserve the order of those items you can put them in an array on the serializing side (probably a server):
An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
Upvotes: 2