gpt4 book ai didi

java - 如何将YouTube播放列表解析为ArrayList

转载 作者:行者123 更新时间:2023-12-03 05:24:45 25 4
gpt4 key购买 nike

我是parsing简单 JSON ,如下所示:

if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);

JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("actors");

for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);

Actors actor = new Actors();

actor.setName(object.getString("name"));
actor.setImage(object.getString("image"));

actorsList.add(actor);
}
return true;
}

这是使用 AsyncTask 执行的 JSON链接:
 new JSONAsyncTask().execute("http://microblogging.wingnity.com/JSONParsingTutorial/jsonActors");

但是现在我必须 parse Youtube JSON Playlist:
 http://gdata.youtube.com/feeds/api/playlists/PLWz5rJ2EKKc9ofd2f-_-xmUi07wIGZa1c?v=2&alt=jsonc

我需要获取一些东西,例如:每个 ,每个视频TitleThumbnailLink
Pojo:
public class Actors {

private String name;
private String image;

public Actors() {

}

public Actors(String name, String image) {
super();
this.name = name;
this.image = image;
}


public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getImage() {
return image;
}

public void setImage(String image) {
this.image = image;
}

}

最佳答案

您会收到这样的响应(使用ChannelId(查询参数)的 IMPT PlayingList响应)

{
"kind": "youtube#playlistListResponse",
"etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/O8-3nTBpPVrsEjyg6BXeSSO2pU0\"",
"pageInfo": {
"totalResults": 3,
"resultsPerPage": 5
},
"items": [
{

"kind": "youtube#playlist",
"etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/06IYq1oWiveiXSEbF8J6Ucf9LYs\"",
"id": "PLFE56E5CE58D71A55",
"snippet": {
"publishedAt": "2012-04-05T17:01:18.000Z",
"channelId": "UCjXfkj5iapKHJrhYfAF9ZGg",
"title": "T&T Elite Canada 2012, April 4, 2012",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/default.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/default.jpg"
}
},
"channelTitle": "AlbertaGymnastics",
"localized": {
"title": "T&T Elite Canada 2012, April 4, 2012",
"description": ""
}
}
}, ... and more items..}

现在为上述json响应创建一个pojo,并从 items数组中读取视频详细信息

关于java - 如何将YouTube播放列表解析为ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31154104/

25 4 0