My JsonArray
structure is like this:
resultArray =
[
{
"key1": [],
"key2": "keyval",
"key3": "keyVal"
},
{
"key1": [],
"key2": "keyval",
"key3": "keyVal"
},
{
"key1": [],
"key2": "keyval",
"key3": "keyVal"
}
]
I am trying add JsonObject
at 1st postion.
JSONObject jo = new JSONObject();
jo.put("aa","bb");
( (JSONObject)resultArray.get(0)).getJSONArray("key1").put(jo);
after executing the above step below is the result.
resultArray = [{ "key1": [{"aa","bb"}] ,"key2":"keyval", "key3":"keyVal" },
{ "key1": [{"aa","bb"}] ,"key2":"keyval", "key3":"keyVal" },
{ "key1": [{"aa","bb"}] ,"key2":"keyval", "key3":"keyVal" } ]
Values are getting added to the all the Items in my JsonArray
.
But I want to add to the specific position.
In above case , I want to add to only at '0' position.
Please let me know if ther's any mistake in below line:
( (JSONObject)resultArray.get(0)).getJSONArray("key1").put(jo);