【发布时间】:2013-06-12 18:32:10
【问题描述】:
我想读这JSON 行但因为它以JSONArray 开头我有点困惑
"abridged_cast": [
{
"name": "Jeff Bridges",
"id": "162655890",
"characters": [
"Jack Prescott"
]
},
{
"name": "Charles Grodin",
"id": "162662571",
"characters": [
"Fred Wilson"
]
},
{
"name": "Jessica Lange",
"id": "162653068",
"characters": [
"Dwan"
]
},
{
"name": "John Randolph",
"id": "162691889",
"characters": [
"Capt. Ross"
]
},
{
"name": "Rene Auberjonois",
"id": "162718328",
"characters": [
"Bagley"
]
}
],
我只需要使用“名称”并将所有内容保存为一个字符串。 (字符串值为:Jeff Bridges、Charles Grodin、Jessica Lange、John Randolph、Rene Auberjonois)。
这是我的代码:
try {
//JSON is the JSON code above
JSONObject jsonResponse = new JSONObject(JSON);
JSONArray movies = jsonResponse.getJSONArray("characters");
String hey = movies.toString();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
【问题讨论】:
-
你能发布完整的 json 字符串吗?
-
您正在使用错误的名称检索数组。
-
应该是
getJSONArray("abridged_cast"),然后是for循环 -
我不小心在我要写“名字”的代码中写了“字符”。