2 回答
![?](http://img1.sycdn.imooc.com/54584f3100019e9702200220-100-100.jpg)
TA贡献1807条经验 获得超9个赞
如果您使用的是 json-simple-1.1.1 jar。这是下面的代码:
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(response);
JSONObject jsonObject = (JSONObject) obj;
//System.out.println(jsonObject.toString());
System.out.println("json size==" + jsonObject.size());
System.out.println("hghgfh" + jsonObject.keySet());
JSONArray jsonArray = (JSONArray)jsonObject.get("responseObj");
for(int i=0; i<jsonArray.size(); i++)
{
JSONObject arrayJsonObject = (JSONObject) jsonArray.get(i);
JSONObject assets = (JSONObject) arrayJsonObject.get("assets");
// read the assets to store
}
}catch (Exception e){
}
![?](http://img1.sycdn.imooc.com/533e4d510001c2ad02000200-100-100.jpg)
TA贡献1827条经验 获得超8个赞
这是一个伪代码。您可以填写此代码中缺少的部分。
String json = "{"responseFlag":1,"responseMsg":"Successfully retrieved data","responseObj":[{"assets":{"asset_since":"","asset_type":"","comments":"","estimated_value":"","material_status":"SINGLE","ownership_of_assets":"","pep":"","source_of_income":""}},{"assets":{"asset_since":"","asset_type":"","comments":"","estimated_value":"","material_status":"SINGLE","ownership_of_assets":"","pep":"","source_of_income":""}}]}";
JSONObject jsonObject = new JSONObject(json);
JSONArray jsonArray = jsonObject.getJSONArray("responseObj");
for(int i=0; i<jsonArray.length(); i++)
{
JSONObject arrayJsonObject = jsonArray.getJSONObject(i);
//insert into your list or array
}
添加回答
举报