【发布时间】:2017-02-13 00:35:49
【问题描述】:
我尝试从 json 数据 (YouTube V3 API) 中获取值。
String jsonText = readFromUrl(channerUrl);// channerUrl = Youtube V3 API Link
JSONObject json = new JSONObject(jsonText);
System.out.println(json.getString("videoId"));
但我的日志中有这个:
I/System.out: org.json.JSONException: No value for videoId
来自 YouTube 的数据是:
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"xxxx"",
"nextPageToken": "xxx",
"pageInfo": {
"totalResults": 321,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"xxxx"",
"id": "xxxx",
"contentDetails": {
"videoId": "The Value Want"
}
}
]
}
为什么我有 No value for videoId ?
谢谢
编辑(也没有用): (jsonText) 是 JSON 数据的链接
JSONObject json = new JSONObject(jsonText);
List<String> list = new ArrayList<String>();
JSONArray array = json.getJSONArray("items");
for(int i = 0 ; i < array.length() ; i++){
list.add(array.getJSONObject(i).getString("contentDetails"));
System.out.println(json.getString("contentDetails"));
}
【问题讨论】: