I am writing a json
file to my external storage. Below code is used to create json
objects and then adding them to json
array
JSONObject jsonObj = new JSONObject();
jsonObj.put("slotid", "1a");
jsonObj.put("updatetime", 1477650798);
jsonObj.put("active", true);
jsonObj.put("adurl", "httpAd");
jsonObj.put("imgurl", "httpImg");
jsonObj.put("hd", false);
jsonObj.put("x", 0);
jsonObj.put("y", 0);
phoneArray.put(jsonObj);
jsobObj.put("slots", phoneArray);
Above code works fine for API24
but when i try to run same code for API 19
then following output occurs
{
"containers": [ ],
"slots": [
{
"slotid": "1a",
"updatetime": 1477650798,
"adurl": "httpAd",
"active": true,
"hd": false,
"y": 0,
"x": 0,
"imgurl": "httpImg"
},
{
"slotid": "1a",
"updatetime": 1477650798,
"adurl": "httpAd",
"active": true,
"hd": false,
"y": 0,
"x": 0,
"imgurl": "httpImg"
}
]
}
My question is why my jsonObjects
are not writing in order? I am successfully getting correct output on API 24
i.e
{
"slots": [
{
"slotid": "1a",
"updatetime": 1477650798,
"active": true,
"adurl": "httpAd",
"imgurl": "httpImg",
"hd": "false",
"x": 0,
"y": 0
},
{
"slotid": "1a",
"updatetime": 1477650798,
"active": true,
"adurl": "httpAd",
"imgurl": "httpImg",
"hd": "false",
"x": 0,
"y": 0
}
],
"containers": []
}
Where should be the problem?