Lets say that I have a JSON object called fruits and this is the content of it:
"fruits":[{
"name":"natural_one",
"kind"{
0:"apple",
1:"banana",
2:"pear"
}
}];
And when I copy the content of the JSONObject in a new ArrayList, the index order changes like the example here below:
"fruits":[{
"kind"{
1:"banana",
2:"pear",
0:"apple"
},
"name":"natural_one"
}];
What do I do to prevent changing index order when copying content takes place?
It is not possible.
The
JSONObjectclass stores the attributes in a hash table, so is not capable of representing the ordering of the attributes in a serial JSON representation. That’s OK because, the JSON spec says that the order of the attributes is not significant.This comes from the origin of JSON, which is Javascript stntax for associative arrays / objects. The entries in a Javascript associative have no defined / significant order.