JSONObject jsonObject = new JSONObject(content);
JSONArray jsonArray = jsonObject.getJSONArray("message");
for(int i =0;i<jsonArray.length(); i++){
JSONObject productObject = jsonArray.getJSONObject(i);
arrayList.add(new Product(
productObject.getString("url"),
productObject.getString("title"),
productObject.getString("description")
));
{
"message":[
{
"id":"hT_nvWreIhg",
"link":"https://www.youtube.com/watch?v=hT_nvWreIhg",
"kind":"youtube#video",
"publishedAt":"2013-05-31T07:00:36.000Z",
"channelId":"UCQ5kHOKpF3-1_UCKaqXARRg",
"channelTitle":"OneRepublicVEVO",
"title":"OneRepublic - Counting Stars",
"description":"Get OneRepublic's new album 'Oh My My,' featuring 'Kids,' 'Wherever I Go' and 'Let's Hurt Tonight:' http://smarturl.it/OhMyMy Listen to the Best of OneRepublic ...",
"thumbnails":{
"default":{
"url":"https://i.ytimg.com/vi/hT_nvWreIhg/default.jpg",
"width":120,
"height":90
},
"medium":{
"url":"https://i.ytimg.com/vi/hT_nvWreIhg/mqdefault.jpg",
"width":320,
"height":180
},
"high":{
"url":"https://i.ytimg.com/vi/hT_nvWreIhg/hqdefault.jpg",
"width":480,
"height":360
}
}
}
]
}
答案 0 :(得分:0)
您需要再打两次getJSONObject
:
JSONObject defaultObject = productObject.getJSONObject("thumbnails").getJSONObject("default")
然后使用
arrayList.add(new Product(
defaultObject.getString("url"),
productObject.getString("title"),
productObject.getString("description")
));