How to create Json using JsonArray and JsonObject
android, json
Solution
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`
Problem
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..