【问题标题】:Annoying JSON parsing Error index 2 out of range烦人的 JSON 解析错误索引 2 超出范围
【发布时间】:2015-06-17 22:33:51
【问题描述】:

我已经想了好几个小时了,但我总是遇到这个烦人的 Error index 2 out of range 错误

我知道有很多关于 stackoverflow 错误的问题,但每个人的代码似乎都有不同的问题

JSONArray platforms = currentMovie.getJSONArray("platforms"); 
for (int y = 0; y < arrayPlatforms.length(); y++) {
    JSONObject currentPlatform = platforms.getJSONObject(i);
    String platform = currentPlatform.getString("name");
    String platformAbv = currentPlatform.getString("abbreviation");

    platforms.add(platform);
    Toast.makeText(getActivity(), ""+ platforms, Toast.LENGTH_SHORT).show();

    platformsAbbreviation.add(platformAbv);
    Toast.makeText(getActivity(), ""+ platformsAbbreviation, Toast.LENGTH_SHORT).show();
}

platforms和platformsAbbreviation都是String ArrayList

谢谢!!!

【问题讨论】:

    标签: java android json


    【解决方案1】:

    看起来你可能有一个错字:

    JSONObject currentPlatform = platforms.getJSONObject(i);

    i 应该是y

    【讨论】:

      猜你喜欢
      • 2019-06-04
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多