我想创建一个JSON结构,这其实是一种JsonArray内的JSONObject。 样品的结构是:
1。
{
REQ:[
{
ctrlId:TXT1
},
{
ctrlId:TXT2
}
]
}
2。
{
REQ:[
{
ctrlId:txt1中,
VAL:VAL1
},
{
ctrlId:TXT2,
VAL:将val2
}
]
}
但我不能够得到it..Any帮助AP preciated ..
解决方案 的JSONObject的obj =新的JSONObject();
JSONArray REQ =新JSONArray();
JSONObject的reqObj =新的JSONObject()
reqObj.put(ctrlId,txt1中);
req.put(reqObj);
reqObj =新的JSONObject();
reqObj.put(ctrlId,TXT2);
req.put(reqObj);
obj.put(REQ,REQ);
的最终目标是 OBJ
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