【问题标题】:How to get the JSON array for data from reddit?如何从reddit获取数据的JSON数组?
【发布时间】:2014-08-05 05:09:31
【问题描述】:

我很难理解 JSON 数组的概念以及如何从 JSON 响应中准确定位特定数组。

所以,我的目标是从 http://www.reddit.com/r/gifs/.json 获取“子”数组中保存的“数据”对象中的“URL”键值,但我不确定如何通过多个级别和把它放在什么东西里。

如果我不得不猜测,我会保存查询的数组,然后我会简单地说 queryArray.children[1][1].URL 来获取第一个数据数组的第一个 URL。

任何使用 reddit 的例子都会非常棒!我真的对 reddit.com 的 JSON 响应的结构感到困惑。

谢谢!

【问题讨论】:

    标签: android json arrays reddit jsonobject


    【解决方案1】:

    您可以使用 JSONObject 和 JSONArray 来解析结果

    String jsonString = "{...}"; //reddit json answer to the request
    JSONObject redditjson = new JSONObject(jsonString);
    JSONArray children = (JSONArray)redditjson .get("children");
    JSONObject data = (JSONObject)children.get(0);
    String url = data.getString("url");
    

    不要忘记在 try/catch 块中使用它

    【讨论】:

      猜你喜欢
      • 2015-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 2023-03-29
      相关资源
      最近更新 更多