android - 在 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");
}
解决方案
您需要进一步迭代
jsonArrayInnings
使用另一个循环,但在您的代码中您使用i
的是父循环。它不会正常工作。
推荐阅读
- android - 设备锁定时启动活动 android 8+
- haskell - Haskell - 使用滑动窗口在 2D 网格上进行模式匹配
- php - 无法从其他选项卡访问 Cookie
- apache-kafka-streams - 检查 StateStore 是否已完全填充
- django - 为什么 __init__() 和 get_context_data() 中对象的属性不同?
- r - 将 dplyr 管道转换为导致“错误:结果的长度必须为 n,而不是 N”的函数。
- linux - TCP 窗口更新被忽略
- rest - 如何通过休息请求获取 Google OAuth 2.0 令牌
- c++ - 使用指向字符的指针并编写函数来分隔文本单词
- charts - 在 Google Charts 中,如何在 arrayToDataTable 中使用标题行,并且还可以为同一个图表提供选项?