java - 从 YouTube API 解析 JSON

标签 java json youtube-api

我有一个网址: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、标题和描述?

最佳答案

http://www.json.org/有一个用 JAVA 实现的解析器。

关于java - 从 YouTube API 解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7652791/

相关文章:

javascript - 使用 Google 的 API 通过 React 创建 YouTube 播放列表

php - 如何使用PHP中的youtube v3 API获取视频统计信息

java - Android 中的 Parse.com 云代码和 HashMap : How to set an array inside Hashmap?

javascript - 在 json 对象数组中查找一个键值,并使用 Angular 返回另一个键值

java - 如何向 Retrofit Java 接口(interface)上的 @GET() 方法传递一些参数?

json - TypeError : <botocore. response.StreamingBody object at 0x7f81898af438> is not JSON serializable

ios - Youtube API v3 search.list 返回不相关的视频 Swift

java - 处理-碰撞后如何去除图像?

java - 在 SQL Server 中更改列的数据类型时保留非空 - Java

java - 切入点格式错误 : Class must not be null