Dev*_*Dev 3 android json android-volley
我试图获取这个 JSON 数组,但没有得到结果。有人可以告诉我如何使用齐射吗?我需要预订中的所有数据。请帮助我实现它。
{
"code": 200,
"savebooking": [
{
"Booking": {
"id": "304",
"contributor_id": "16",
"table_of_content_id": "6791",
"composition_id": "7469",
"completion": "2017-06-30",
"approved": null,
"cdn_id": "328301423",
"secret_token": "s-riQMc",
"uploaded_on": "2017-06-16 07:51:35",
"created": "2017-06-16 07:48:31",
"modified": "2017-06-16 07:51:35"
}
},
{
"Booking": {
"id": "305",
"contributor_id": "16",
"table_of_content_id": "6791",
"composition_id": "7470",
"completion": "2017-06-30",
"approved": null,
"cdn_id": "328318377",
"secret_token": "s-naSse",
"uploaded_on": "2017-06-16 10:43:39",
"created": "2017-06-16 07:48:31",
"modified": "2017-06-16 10:43:39"
}
},
{
"Booking": {
"id": "306",
"contributor_id": "16",
"table_of_content_id": "6791",
"composition_id": "7471",
"completion": "2017-06-30",
"approved": null,
"cdn_id": null,
"secret_token": null,
"uploaded_on": null,
"created": "2017-06-16 07:48:31",
"modified": "2017-06-16 07:48:31"
}
},
{
"Booking": {
"id": "307",
"contributor_id": "16",
"table_of_content_id": "6791",
"composition_id": "7472",
"completion": "2017-06-30",
"approved": null,
"cdn_id": null,
"secret_token": null,
"uploaded_on": null,
"created": "2017-06-16 07:48:31",
"modified": "2017-06-16 07:48:31"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
如何使用 volley 解析此 JSON 响应?我已经尝试过但没有得到结果。
StringRequest postStringRequest = new StringRequest(Request.Method.POST, BOOK_API,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Response Check :" + response);
try {
JSONObject json = new JSONObject(response);
JSONObject booking = json.getJSONArray("savebooking").getJSONObject("Booking");
Log.d(TAG, "booking Response Check :" + booking);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Run Code Online (Sandbox Code Playgroud)
小智 6
这是
//Here is main response object
JSONObject json = new JSONObject(response);
//now get your json array like this
JSONArray booking = json.getJSONArray("savebooking");
Run Code Online (Sandbox Code Playgroud)
// 现在检查数组长度 > 0
if(booking.length ()> 0){
for(int countItem = 0;countItem<booking.length;countItem++){
JSONObject bookingObject = booking.getJsonObject(countItem);
String id = bookingObject.isNull("id")?"":bookingObject.optString("id");
list.add(id);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8203 次 |
| 最近记录: |