[{“ serviceData”:[{“ id”:“ 1”,“ service_name”:“管道工”,“ act_stat”:“ 1”},]}] 如何获得这个json结构
答案 0 :(得分:1)
String jsonString;
JSONArray jsonArray= new JSONArray(jsonString;);
for(int i=0;i<jsonArray.length();i++)
{
JSONObject jsono= (JSONObject) jsonArray.get(i);
JSONArray ServiceArray= (JSONArray ) jsono.get(i);
for(int j=0;j<ServiceArray.length();j++)
{
String id=jsonobject.getString("id");
String service_name=jsonobject.getString("service_name");
String act_stat=jsonobject.getString("act_stat");
}
}
您可以参考这篇文章:How to Parse the JSON String Android了解更多详情
答案 1 :(得分:0)
首先从 JSONArray 获取 JSONObject ,然后从该 JSONObject 获取特定字段,如下所示:
JSONObject jsonObj = new JSONObject(jsonStr);
SONArray jArray = jsonObj.getJSONArray("serviceData");
for (int i = 0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
String id = jObject.getString("id");
String service_name = jObject.getString("service_name");
String act_stat = jObject.getString("act_stat");
}
答案 2 :(得分:0)
首先从 JSONArray 获得 JSONObject ,然后从该 JSONObject 获得特定字段,如下所示:
JSONArray array;
for(int n = 0; n < array.length(); n++)
{
JSONObject object = array.getJSONObject(n);
String id = object .getString("id");
String service_name = object .getString("service_name");
String act_stat = object .getString("act_stat");
}