无法为Android项目找到正确的JSON路径

时间:2017-08-19 14:20:23

标签: java android json xml

JSONObject baseJsonResponse = new JSONObject(newsJSON);

JSONObject responseObj = baseJsonResponse.getJSONObject("response");

JSONArray resultArray = responseObj.getJSONArray("results");
for (int i =0;i<resultArray.length();i++){

String sectionName = resultArray.getString("sectionName");}

我想获取此网址的部分名称: https://content.guardianapis.com/search?api-key=e11b8d10-d6ef-4fb7-9c12-094c58d37687

1 个答案:

答案 0 :(得分:0)

你可以像这样获得Json Value。

JSONObject baseJsonResponse = new JSONObject(newsJSON);

    JSONObject responseObj = null;
    try {
        responseObj = baseJsonResponse.getJSONObject("response");
        JSONArray resultArray = responseObj.getJSONArray("results");
        int size = resultArray.length();

        for (int i =0;i<size;i++){
            JSONObject myJson = resultArray.getJSONObject(i);
            String sectionName = myJson.getString("sectionName");
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
相关问题