如何过滤JSON listview

时间:2016-11-06 18:51:59

标签: android arrays json objectlistview

我想要的是在列表中显示equals(London)所在的字符串:

String location =  respons.getString("location"); 

如果它等于曼彻斯特,我不希望它在列表中:

for (int i = 0; i < jsonArray.length(); i++) {

    JSONObject respons =jsonArray.getJSONObject(i);  
    String id = respons.getString("id");
    String location =  respons.getString("location");
    String info = respons.getString("name");
    String img = respons.getString("img");

    listitmes.add(new Listitme(id, location, info, img));
    listAllItme();

}

1 个答案:

答案 0 :(得分:0)

JSONObject respons =jsonArray.getJSONObject(i);
// do your test hire if respons.getString("location") equlas the String "manchestar"
if(respons.getString("location").equlas("manchestar")){
    String id=respons.getString("id");
    String info=respons.getString("name");
    String img=respons.getString("img");
    listitmes.add(new Listitme(id,location,info,img));
    listAllItme();
}