Possible Duplicate:
Sort JavaScript object by key
I am creating JSONArray from JSONObject in android. The JSONArray that i wanted to be is:
[{“last_name”:”cruz”,
“first_name”:”juan”,
“middle_name”:”sam”}]
but it appears
[{“first_name”:”cruz”,
“last_name”:”juan”,
“middle_name”:”sam”}]
how can I arrange the array in order that I wanted?
Thanks…
Example:
download this library:
https://github.com/douglascrockford/JSON-java
save all the files in a new package in your project
instead of using org.json.JSONObject use your.package.JSONObject which you added from the downloaded library.
now open JSONObject.java file and change HashMap() to LinkedHashMap() in the constructor
This will make the JSONObject store data in the order you entered the values using put.