【问题标题】:Parsing JSON response without an array name解析没有数组名的 JSON 响应
【发布时间】:2014-07-18 10:48:20
【问题描述】:
[
  {

    "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 解析器可以正常工作)。

【问题讨论】:

  • 这不是问题。
  • 开发人员无法解析此 JSON :D ..请提供更多信息
  • 请先搜索一下我觉得这是个老问题stackoverflow.com/questions/18977144/…
  • 解析这个数组,不需要任何name

标签: android json


【解决方案1】:

用于解析这种类型的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);
}  

这可能对你有帮助……

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-29
    • 2020-08-09
    • 1970-01-01
    • 2020-01-08
    • 2011-05-20
    • 1970-01-01
    • 2021-11-13
    • 2021-08-15
    相关资源
    最近更新 更多