2015-09-10 78 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