I'm trying to put a JSONObject inside a JSONArray in Java. Here is my two objects:
JSONArray:
[{
"url": null,
"flag": "0",
"read": "0",
"time": 2000,
"exp": null,
"population": 10
}]
JSONObject:
{
"events": [
{
"color": "Green",
"event": "Restart"
},
{
"color": "Black",
"event": "Shutdown"
},
{
"color": "White",
"event": "Read"
}
]
}
Expected result:
[
{
"url": null,
"flag": "0",
"read": "0",
"time": 2000,
"exp": null,
"population": 10,
"events": [
{
"color": "Green",
"event": "Restart"
},
{
"color": "Black",
"event": "Shutdown"
},
{
"color": "White",
"event": "Read"
}
]
}
]
I tried to use this code, but the result is not ok:
jsonArray.put(jsonObject);
Unexpected result:
[
{
"url": null,
"flag": "0",
"read": "0",
"time": 2000,
"exp": null,
"population": 10
},
{
"events": [
{
"color": "Green",
"event": "Restart"
},
{
"color": "Black",
"event": "Shutdown"
},
{
"color": "White",
"event": "Read"
}
]
}
]
The "events" key-value most be inside the unique element in JSONArray, not as another element.