JSON order mixed up
java, json
Solution
You cannot and should not rely on the ordering of elements within a JSON object.
From the JSON specification at https://www.json.org/
An object is an unordered set of name/value pairs
As a consequence, JSON libraries are free to rearrange the order of the elements as they see fit. This is not a bug.
Problem
I've a problem trying to make my page printing out the `JSONObject` in the order i want. In my code, I entered this: ``` JSONObject myObject = new JSONObject(); myObject.put("userid", "User 1"); myObject.put("amount", "24.23"); myObject.put("success", "NO"); ``` However, when I see the display on my page, it gives: JSON formatted string: `[{"success":"NO", "userid":"User 1", "bid":24.23}]` I need it in the order of userid, amount, then success. Already tried re-ordering in the code, but to no avail. I've also tried `.append`....need some help here thanks!!