{
"Response":"success",
"errorText":null,
"TotalBooks":null,
"privateBookStore":{
"privateBooks":[
{
"Shopid":76354,
"Shopname":"xyz",
"Term":null,
"“Strategy":[
{
"Name":"ABC",
"ID":9
}
],
"magaerTYpe":"Single",
"Freq":"”monthly”",
"StructureType":{
"Name":"ABC",
"ID":9
},
"Currency":[
"USD",
"EURO",
"RUPYEE"
]
}
]
}
}
我尝试过使用 JsonObject 和 JsonArray 但响应格式包含多个 JsonArray 和 JsonObject 一起
我尝试使用 HashMap 和 List 但它不适合我。循环遍历多个 JsonObject我也经历过这个。请建议方法
到目前为止我所拥有的是 -
inputstream in = new bufferedinputstream(urlconnection.getinputstream());
String result = ioutils.tostring(in utf-8 );
JSONObject outer = new JSONObject(result);
JSONObject inner = outer.getJSONObject("privateBookStore");
JSONArray arr = inner.getJSONArray("privateBooks");
也试过这个,但没有给我键:值对结构
List<HashMap<String,String>> response = new ArrayList<>();
JSONArray jsonarray = null;
try {
jsonarray = new JSONArray(json);
for(int i=0;i<jsonarray.length();i++) {
JSONObject jsonObject = jsonarray.getJSONObject(i);
Iterator<?> iterator = jsonObject.keys();
HashMap<String,String> map = new HashMap<>();
while (iterator.hasNext()) {
Object key = iterator.next();
Object value = jsonObject.get(key.toString());
map.put(key.toString(),value.toString());
}
response.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}