首页 > 解决方案 > 在 android 中使用 volley 库解析嵌套的 JSON 数组

问题描述

如何使用 volley 库解析嵌套的 JSON 数组?我的 JSON 数据结构截图。 https://prnt.sc/pbaea5

我需要坚持得分值。

JSONArray jsonArray = response.getJSONArray("matches");

    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonObjectMatchs = jsonArray.getJSONObject(i);

        // bat_team node is JSON Object
        JSONObject bat_teamData = jsonObjectMatchs.getJSONObject("bat_team");
        JSONArray jsonArrayInnings = bat_teamData.getJSONArray("innings");
        JSONObject jsonObjectInnings = jsonArrayInnings.getJSONObject(i);


        String bat_team_score = jsonObjectInnings.getString("score");
    }

标签: androidjsonandroid-volley

解决方案


您需要进一步迭代 jsonArrayInnings使用另一个循环,但在您的代码中您使用i的是父循环。它不会正常工作。


推荐阅读