请问这样的json数据怎么解析出来

2025-04-14 09:35:44
推荐回答(2个)
回答1:

简单的给你做了下解析,具体要解析到什么程度,你自己看吧。大概解析方法就是这样的:
如下:
privatevoid testJson(){
String JsonData = "[{\"id\":[\"386\",\"381\",\"379\",\"377\"],\"num\":[\"386\",\"381\",\"379\",\"377\"]},{\"id\":[\"3860\",\"3810\",\"3790\",\"3770\"],\"num\":[\"3860\",\"3810\",\"3790\",\"3770\"]}]";
JSONObject obj = null;
JSONArray jsonArary;
try {
jsonArary = new JSONArray(JsonData);
for(int i=0;iobj = jsonArary.getJSONObject(i);
//取ID
JSONArray strID = obj.getJSONArray("id");
for(int j=0;jLog.v("ID:", strID.get(j).toString());
}
//取num
JSONArray strNum = obj.getJSONArray("num");
for(int k=0;kLog.v("NUM:", strNum.get(k).toString());
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}

回答2:

public struct Person
{
public string Name {get;set;}
public string Sex {get;set;}
}

public struct Information
{
public string Address {get;set;}
public string Phone {get;set;}
}

public struct Test
{
public string cd {get;set;}
public string ph {get;set;}
}

//主解析对象1
public struct JsonModel1
{
public List {get;set;}
public List {get;set;}
public List {get;set;}
}

public struct JsonModel2
{
public string Status {get;set;}
public List {get;set;}
public List {get;set;}
public List {get;set;}
}