org.json.JSONException:没有儿童的价值

时间:2016-12-27 16:12:55

标签: android

我正在尝试从reddit(https://www.reddit.com/r/gifs/.json)获取json文件中的数据。但我一直得到同样的错误:

  

org.json.JSONException:没有儿童价值

这是我的代码:

RequestQueue queue = Volley.newRequestQueue(this);
String url ="https://www.reddit.com/r/funny.json";

JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
  @Override
  public void onResponse(JSONObject response) {
    try {
      JSONArray children =  response.getJSONArray("children");
    } catch (JSONException e) {
      e.printStackTrace();
      Log.i(TAG, "ERROR !!!!" + e);
    }
  }
}, new Response.ErrorListener() {
      @Override
      public void onErrorResponse(VolleyError error) {
        Log.i(TAG, "ERROR");
      }
});

queue.add(jsObjRequest);

如果有人可以帮助我,那就太好了!

2 个答案:

答案 0 :(得分:0)

您应该这样做,因为childrendata对象的孩子

JsonObject data = response.getJsonObject("data");
JsonArray children = data.getJsonArray("children");

答案 1 :(得分:0)

执行此操作,因为数组位于数据对象

requests.add(new Request().setAddSheet(...));
requests.add(new Request().setUpdateCells(...));
相关问题