[英]How to parse this Json using Gson?
I know how to parse json but I can not solve integer json field in this json.我知道如何解析 json 但我无法解决此 json 中的整数 json 字段。 Because this json contain integer field(23254,23998).
因为这个 json 包含整数字段(23254,23998)。
Here my JSON这是我的 JSON
{
"status":"OK",
"alarms":{
"23254":[
{
"speed_limit":250,
"acc_limit":null,
"dcc_limit":null,
"idle_limit":null
}
],
"23998":[
{
"speed_limit":120,
"acc_limit":null,
"dcc_limit":null,
"idle_limit":null
}
]
}
}
Parse the Json object like this way像这样解析Json对象
JSONObject obj= new JSONObject(content);
Iterator iterator = obj.keys();
while(iterator.hasNext()){
String key = (String)iterator.next();
JSONObject object1 = obj.getJSONObject(key);
// get id from object1
String _pubKey = object1.optString("id");
}
try{
JSONObject j=new JSONObject("here put your response string");
JSONObject j1= j.getJSONObject("alarms");
ArrayList<String> arr=new ArrayList<String>();
Iterator iter = j1.keys();
while(iter.hasNext()){
String key = (String)iter.next();
arr.add(j1.getJSONArray(key).toString());
System.out.println("json"+j1.getJSONArray(key).toString());
}
}catch (JSONException e){
e.printStackTrace(); e.printStackTrace(); }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.