【问题标题】:Android Json Handling issueAndroid Json 处理问题
【发布时间】:2020-10-16 20:52:53
【问题描述】:

只有当文件夹数组中的密码值为空时,我才想向用户显示 updated_at 数据。

JSONArray jsonArray = object.getJSONArray("data");
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject dataa = jsonArray.getJSONObject(i);


                                JSONArray jsonArray2 = dataa.getJSONArray("folder");
                                for (int i2 = 0; i2 < jsonArray.length(); i2++)
                                {
                                    JSONObject dataa2 = jsonArray2.getJSONObject(i2);
                                    String password = dataa2.getString("password");
                                    if (password.equals("null") || password.equals(null))
                                    {
                                        //Display data
                                    }
                                    else
                                    {
                                        // dont Display data
                                    }
}

有办法吗?

【问题讨论】:

  • for (int i2 = 0; i2 &lt; jsonArray.length(); i2++) 改为for (int i2 = 0; i2 &lt; jsonArray2.length(); i2++)
  • 哈哈哈,花时间在这真是个愚蠢的错误,非常感谢

标签: android arrays json android-studio


【解决方案1】:

纠正你的内部循环条件部分。

JSONArray jsonArray2 = dataa.getJSONArray("folder");
for (int i2 = 0; i2 < jsonArray2.length(); i2++)
          {
              JSONObject dataa2 = jsonArray2.getJSONObject(i2);

【讨论】:

  • 哈哈哈,花时间在这真是个愚蠢的错误,非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-23
  • 1970-01-01
  • 1970-01-01
  • 2019-01-20
相关资源
最近更新 更多