【问题标题】:How get a specific item from an JSONArray如何从 JSONArray 中获取特定项目
【发布时间】:2015-09-10 08:44:06
【问题描述】:

我有这些 JSONArray

[
  {
    "cid": "6",
    "pid": "0",
    "nid": "28",
    "uid": "1",
    "subject": "ciaooo",
    "hostname": "62.98.160.246",
    "created": "1441816543",
    "changed": "1441816543",
    "status": "1",
    "thread": "04/",
    "name": "uniwalltest",
    "mail": "",
    "homepage": "",
    "language": "und",
    "uri": "http://uniwalltest.altervista.org/portale/?q=app/comment/6"
  },
  {
    "cid": "5",
    "pid": "0",
    "nid": "28",
    "uid": "1",
    "subject": "rhdhdhdjj cisioos",
    "hostname": "62.98.160.246",
    "created": "1441816301",
    "changed": "1441816301",
    "status": "1",
    "thread": "03/",
    "name": "uniwalltest",
    "mail": "",
    "homepage": "",
    "language": "und",
    "uri": "http://uniwalltest.altervista.org/portale/?q=app/comment/5"
  }
]

我不会只显示带有 nid 28 的项目主题,这是我的代码:

        for(int j=0;j<result.length();j++) {
            try {

                title.add(result.getJSONObject(j).getString("subject").toString());


            } catch (Exception e) {
                Log.v("Error", e.getMessage());
            }
        }

谢谢,

【问题讨论】:

标签: java android arrays json


【解决方案1】:

为什么不使用简单的 if 条件:

if ("28".equals(result.getJSONObject(j).getString("nid")) {
    title.add(result.getJSONObject(j).getString("subject").toString());
}

【讨论】:

    猜你喜欢
    • 2012-04-15
    • 2014-11-08
    • 2015-09-20
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-12
    • 2011-12-11
    相关资源
    最近更新 更多