I want to create a Json structure which is actually a JsonArray inside a JsonObject. The sample structure is:
1.
{
“req”: [
{
“ctrlId”:”txt1”
},
{
“ctrlId”:”txt2”
}
]
}
2.
{
“req”: [
{
“ctrlId”:”txt1”,
“val” : “val1”
},
{
“ctrlId”:”txt2”,
“val” : “val2”
}
]
}
But i am not able to get it..Any help is appreciated..
JSONObject obj = new JSONObject();
JSONArray req = new JSONArray();
JSONObject reqObj = new JSONObject()
reqObj.put( "ctrlId", "txt1" );
req.put( reqObj );
reqObj = new JSONObject();
reqObj.put( "ctrlId", "txt2" );
req.put( reqObj );
obj.put( "req", req );
The final object is obj
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With