我有這樣的JSON飼料解析:深JSON解析在Android
{
"movies": [{
"id": "770810965",
"title": "Invictus",
"year": 2009,
"mpaa_rating": "PG-13",
"runtime": 134,
"critics_consensus": "Delivered with typically stately precision from director Clint Eastwood, Invictus may not be rousing enough for some viewers, but Matt Damon and Morgan Freeman inhabit their real-life characters with admirable conviction.",
"release_dates": {
"theater": "2009-12-11",
"dvd": "2010-05-18"
},
"ratings": {
"critics_rating": "Certified Fresh",
"critics_score": 76,
"audience_rating": "Upright",
"audience_score": 75
},
"synopsis": "",
"posters": {
"thumbnail": "http://content7.flixster.com/movie/10/92/27/10922777_mob.jpg",
"profile": "http://content7.flixster.com/movie/10/92/27/10922777_pro.jpg",
"detailed": "http://content7.flixster.com/movie/10/92/27/10922777_det.jpg",
"original": "http://content7.flixster.com/movie/10/92/27/10922777_ori.jpg"
},
"abridged_cast": [{
"name": "Morgan Freeman",
"id": "162652224",
"characters": ["Nelson Mandela"]
}, {
"name": "Matt Damon",
"id": "162653499",
"characters": ["Francois Pienaar"]
}, {
"name": "Tony Kgoroge",
"id": "528345122",
"characters": ["Jason Tshabalala"]
}, {
"name": "Patrick Mofokeng",
"id": "770837270",
"characters": ["Linga Moonsamy"]
}, {
"name": "Matt Stern",
"id": "770867648",
"characters": ["Hendrick Booyens"]
}],
"alternate_ids": {
"imdb": "1057500"
},
"links": {
"self": "http://myProjectmobiletest.herokuapp.com/api/public/v1.0/movies/770810965.json",
"alternate": "http://www.rottentomatoes.com/m/invictus/",
"cast": "http://myProjectmobiletest.herokuapp.com/api/public/v1.0/movies/770810965/cast.json",
"clips": "http://myProjectmobiletest.herokuapp.com/api/public/v1.0/movies/770810965/clips.json",
"reviews": "http://myProjectmobiletest.herokuapp.com/api/public/v1.0/movies/770810965/reviews.json",
"similar": "http://myProjectmobiletest.herokuapp.com/api/public/v1.0/movies/770810965/similar.json"
}
},
我檢索字段標題和梗概是這樣的:
try{
jsonResponse = new JSONObject(response);
JSONArray jsonTitleNode = jsonResponse.optJSONArray("movies");
lengthJsonArr = jsonTitleNode.length();
for(int i = 0; i < lengthJsonArr; i++){
JSONObject jsonChildNode = jsonTitleNode.getJSONObject(i);
movieTitle = jsonChildNode.optString("title").toString();
movieSynopsis = jsonChildNode.optString("synopsis").toString();
mListTitle.add(movieTitle);
mListSynopsis.add(movieSynopsis);
}
}
mListTitle和mListSynopsis包含了我想要的清單它運作良好。現在,我想檢索我的JSON數組中的一些更深的字段,如「abridget_cast」節點內的演員的「名稱」和最後一個字段「similar」。謝謝你,如果你能幫我做到這一點。