2015-09-10 54 views
-5

得到一个特定的项目我有这些JSONArray如何从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()); 
      } 
     } 

谢谢,

+0

检查http://github.com/mohit008/Android-Json-例子 – Mohit

+0

JSONArray的关键是什么? – Rajesh

回答

1

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

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

我已经试过没有成功 – Corax

+0

它的工作,我忘了指定NID号码谢谢 – Corax