【发布时间】:2011-11-30 22:54:02
【问题描述】:
我有一个 URL:https://gdata.youtube.com/feeds/api/users/charlieissocoollike/uploads?alt=jsonc&v=2,它提供有关用户最新 youtube 上传的 JSON 信息。
我已经编写了一些代码来解析这个 JSON 数据,但我不明白 JSON 是如何工作的以及如何在 Java 中解析它。
public void getVideoData() throws ClientProtocolException, JSONException, IOException {
JSONObject object = (JSONObject) new JSONTokener(getVideoJSON().toString()).nextValue();
//String query = object.getString("data");
JSONArray locations = object.getJSONArray("data");
output.setText(locations.getString(1));
}
public JSONObject getVideoJSON () throws ClientProtocolException, IOException, JSONException {
final String URL = "https://gdata.youtube.com/feeds/api/users/charlieissocoollike/uploads?alt=jsonc&v=2";
StringBuilder url = new StringBuilder(URL);
HttpGet get = new HttpGet(url.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
HttpEntity e = r.getEntity();
String data = EntityUtils.toString(e);
JSONArray VideoData = new JSONArray(data);
JSONObject video = VideoData.getJSONObject(0);
return video;
}
我应该如何从每个视频对象的 JSON 数据中提取视频 id、标题和描述?
【问题讨论】:
标签: java json youtube-api