使用android获取JSON值

使用android获取JSON值

{"SrchResults":[{"FeatCount":"53"},{"NAME":"Dengue_Cluster","Number of cases":"10","HYPERLINK":"http://www.dengue.gov.sg/cms/ehd/20131647.jpg ","DESCRIPTION":"Ang Mo Kio Ave 3 (Blk 126, 127, 128) / Ang Mo Kio Ave 6 (Blk 124, 125)","MAPTIP":"Dengue_Cluster","SYMBOLCOLOR":"#E600A9","XY":"29342.6037999997,39300.7427999992"}{"NAME":"Dengue_Cluster","Number of cases":"11","HYPERLINK":"http://www.dengue.gov.sg/cms/ehd/20131578.jpg ","DESCRIPTION":"Guillemard Rd / Lor 28 Geylang / Lor 30 Geylang","MAPTIP":"Dengue_Cluster","SYMBOLCOLOR":"#E600A9","XY":"33644.5215999996,32574.9587999992"}]}


如何提取以上数据?我想得到


名称
案件数
超连结
描述
Maptip
y

最佳答案

{ // json object node
    "SrchResults": [ // jsona array
        {
            "FeatCount": "53"
        },
        {             // json object node
            "NAME": "Dengue_Cluster",    // string
            "Number of cases": "10",
            "HYPERLINK": "http://www.dengue.gov.sg/cms/ehd/20131647.jpg ",
            "DESCRIPTION": "Ang Mo Kio Ave 3 (Blk 126, 127, 128) / Ang Mo Kio Ave 6 (Blk 124, 125)",
            "MAPTIP": "Dengue_Cluster",
            "SYMBOLCOLOR": "#E600A9",
            "XY": "29342.6037999997,39300.7427999992"
        },
        {
            "NAME": "Dengue_Cluster",
            "Number of cases": "11",
            "HYPERLINK": "http://www.dengue.gov.sg/cms/ehd/20131578.jpg ",
            "DESCRIPTION": "Guillemard Rd / Lor 28 Geylang / Lor 30 Geylang",
            "MAPTIP": "Dengue_Cluster",
            "SYMBOLCOLOR": "#E600A9",
            "XY": "33644.5215999996,32574.9587999992"
        }
    ]
}


托帕斯

      try
      {
          JSONObject jObj = new JSONObject("My Json string");
          JSONArray jr = jObj.getJSONArray("SrchResults");
          JSONObject json = (JSONObject) jr.get(0);
          String key = json.getString("FeatCount");
          Log.i("...........",key);
          for(int i=1;i<jr.length();i++)
          {
              JSONObject jb= jr.getJSONObject(i);
              String name = jb.getString("NAME");
              String nofcase = jb.getString("Number of cases");
              Log.i("Name is....",name);
              Log.i("No of cases .........",nofcase);

          }
          }catch(Exception e)
      {
          e.printStackTrace();
      }


日志记录

12-08 09:53:32.212: I/...........(30147): 53
12-08 09:53:32.212: I/Name is....(30147): Dengue_Cluster
12-08 09:53:32.212: I/No of cases .........(30147): 10
12-08 09:53:32.222: I/Name is....(30147): Dengue_Cluster
12-08 09:53:32.222: I/No of cases .........(30147): 11

关于java - 使用android获取JSON值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20451819/

10-10 10:48