Moin Khan Moin Khan - 1 year ago 103
JSON Question

Why Json Object order mixed up in android KITKAT and below versions?

I am trying to send these

to server for login and its working like a charm in android lollipop and marshmallow but when I trying to login in android kitkat and below version then its giving incorrect username and password error because of json order mixup. How can I solve that ?

JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("USERName", username);
jsonObject.put("LOGINPASSWORD", password);
jsonObject.put("IMEINUMBER1", imeino);
jsonObject.put("Latitude", latitude);
jsonObject.put("Longitude", longitude);
} catch (JSONException e) {

Below is my
which mixup in Android Kitkat and below versions.


Answer Source

a JSONObject doesn't guarantee any order for its keys, it may sometimes be in the order of insertion, and sometimes not.

If you need to keep the order of insertion, use a JSONArray instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download