{ " UserName":" abcd", "密码":" hjhdfg", " int1":1, " mydate":" 2017-12-12T00:00:00", " mydecimal":2.3, " id":" 00000000-0000-0000-0000-000000000000", "列出PODetails":[ { "姓名":" mohit", " Id":1 } ] }
{ RequestQueue requestQueue = Volley.newRequestQueue(this);
//this is the code to write
JSONObject mRequestBody = new JSONObject();
try {
poDetails = new ArrayList<>();
mRequestBody.put("UserName", "abhishek");
mRequestBody.put("Password", "dvjndsjs");
mRequestBody.put("int1", 1);
mRequestBody.put("mydate", date_time.dateFormatter);
mRequestBody.put("mydecimal", 0.0);
mRequestBody.put("id", idOne);
List<String> PODetails = (List<String>)
mRequestBody.getJSONArray("PODetails");
块引用 Log.e(&#34; POdetails&#34;,PODetails.toString());}
答案 0 :(得分:0)
{
"UserName": "abcd",
"Password": "hjhdfg",
"int1": 1,
"mydate": "2017-12-12T00:00:00",
"mydecimal": 2.3,
"id": "00000000-0000-0000-0000-000000000000",
"List PODetails": [{
"Name": "mohit",
"Id": 1
}]
}
根据你的JSON,你需要这样做。
try {
JSONObject mRequestBody = new JSONObject();
mRequestBody.put("UserName", "abhishek");
mRequestBody.put("Password", "dvjndsjs");
mRequestBody.put("int1", 1);
mRequestBody.put("mydate", date_time.dateFormatter);
mRequestBody.put("id", idOne);
mRequestBody.put("mydecimal", 0.0);
JSONArray podDetailsArray = new JSONArray();
podDetailsArray.put(new JSONObject().put("Name", "mohit").put("Id",1));
} catch (JSONException e) {
e.printStackTrace();
}