Moin Khan Moin Khan - 1 month ago 8x
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.



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.