tags:

views:

26

answers:

1

Hi,

I've a problem trying to making 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!!

+1  A: 

JavaScript objects, and JSON, have no way to set the order for the keys. You might get it right in Java (I don't know how Java objects work, really) but if it's going to a web client or another consumer of the JSON, there is no guarantee as to the order of keys.

Mark Snidovich