解析没有数组名称的JSON响应

时间:2014-07-18 10:48:21

标签: android json

[
  {

    "stDescription": "END N/A",
    "stCategory": "6",
    "sZone": "@",
    "sIncident": "0"
  },
  {

    "stDescription": "BEG N/A",
    "stCategory": "6",
    "sZone": "@",
    "sIncident": "0"
  },
  {

    "stDescription": "",
    "stCategory": "Null",
    "sZone": "4",
    "sIncident": "0"
  },
  {

    "stDescription": "",
    "stCategory": "Null",
    "sZone": "5",
    "sIncident": "0"
  }
]

这里没有数组名称,但我想解析整个数组(如果我使用数组名称,我的JSON解析器工作正常)。

1 个答案:

答案 0 :(得分:0)

用于解析此类JSON ...

首先将其存储在String ..

然后执行以下过程...

String str = "JSON STRING";
JSONArray jsonarray = new JSONArray(str);

for(int i=0; i<jsonarray.length(); i++){
    JSONObject obj = jsonarray.getJSONObject(i);

    String stDescription = obj.getString("stDescription");
    String stCategory= obj.getString("stCategory");
    //and other fields

    System.out.println(stDescription);
    System.out.println(stCategory);
}  

这可能对你有所帮助......