我需要你的幫助來解析嵌套的JSON對象。嵌套的JSON對象解析在android中使用volley
附JSON數據:
{
"31": {
"basic": {
"node_id": "31",
"title": "test",
"alias": "test",
"description": "test",
"site_id": "151336557",
"node_type": "7",
"privacy": "7",
"deleted": "0",
"status": "1",
"created_date": "1379169518",
"updated_date": "1379169518",
"created_by": "140513626519686828",
"updated_by": null,
"readable_date": "14th Sep, 2013"
},
"meta": {
"forum_id": "61"
},
"comments": {
"count": 1
},
"likes": {
"count": 0
},
"tags": [],
"node_id": "31"
},
"32": {
"basic": {
"node_id": "32",
"title": "testing discussion",
"alias": "testing-discussion",
"description": "testing",
"site_id": "151336557",
"node_type": "7",
"privacy": "7",
"deleted": "0",
"status": "1",
"created_date": "1379493816",
"updated_date": "1379493816",
"created_by": "140513795022034166",
"updated_by": null,
"readable_date": "18th Sep, 2013"
},
"meta": {
"forum_id": "65"
},
"comments": {
"count": 1
},
"likes": {
"count": 0
},
"tags": [],
"node_id": "32"
}
}
附加Java代碼:
private void makeJsonObjectRequest() {
showpDialog();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET, urlJsonObj, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
JSONObject phone = response.getJSONObject("31").getJSONObject("basic");
String name = phone.getString("title");
String email = phone.getString("description");
JSONObject comments = response.getJSONObject("31").getJSONObject("comments");
String home = comments.getString("count");
JSONObject like = response.getJSONObject("31").getJSONObject("likes");
String mobile = like.getString("count");
jsonResponse = "";
jsonResponse += "Name: " + name + "\n\n";
jsonResponse += "Email: " + email + "\n\n";
jsonResponse += "Home: " + home + "\n\n";
jsonResponse += "Mobile: " + mobile + "\n\n\n";
txtResponse.setText(jsonResponse);
我需要檢索所有的對象,但我在這裏只獲取一個對象(我的意思是所有node_id
S) 。我需要你的建議。 謝謝。
使用本網站http://www.jsonschema2pojo.org/,它可以幫助你從Json的轉換爲對象 – 2014-10-10 11:45:22