获取过滤的json值

时间:2015-12-16 13:57:52

标签: java json

我有以下json。我想只得到category:Accident的标题。我保留了一个comboBox frm,用户可以在其中过滤结果。如果选择了意外,只显示事故类别的标题。我怎么能得到它?

JSON:

     [{"category":"Accident","title":"Accident 1"},
      {"category":"Accident","title":"Accident 2"},
        {"category":"Lost","title":"Lost 1"},
        {"category":"Lost","title":"Lost 2"}]

代码:

JSONParser p = new JSONParser();
results = p.parse(new InputStreamReader(input));
response = (Vector<Map<String, Object>>) results.get("root");
for (int i = 0; i < response.size(); i++) {
    Hashtable hm = (Hashtable) response.get(i);
    HashMap<String, Object> anItem = new HashMap<String, Object>();

    category = hm.get("category").toString();
    String title = hm.get("title").toString();

    anItem.put("category", category);
    anItem.put("title", title);

    listRender.add(anItem); //listRender is an arraylist
}}};

connectionRequest.setPost(false);
connectionRequest.setUrl("http://bbb.com");
connectionRequest.setDuplicateSupported(true);
NetworkManager.getInstance().addToQueueAndWait(connectionRequest);

0 个答案:

没有答案