[英]How to convert JsonArray to ArrayList but JsonObject In JsonArray is not the same structure
我如何將下面具有不同JsonObject's
JsonArray
轉換為Single Arraylist
[{
"type": "textCard",
"data": {
"dataType": "TextCard",
"id": 0,
"type": "header5",
"text": "",
"subTitle": null,
"actionUrl": null,
"adTrack": null,
"follow": null
},
"tag": null,
"id": 0,
"adIndex": -1
},
{
"type": "briefCard",
"data": {
"dataType": "BriefCard",
"id": 30,
"icon": "*jpeg",
"iconType": "square",
"title": "#",
"subTitle": null,
"description": "",
"actionUrl": "B8%B8%E6%88%8F",
"adTrack": null,
"follow": {
"itemType": "category",
"itemId": 30,
"followed": false
},
"ifPgc": false
},
"tag": null,
"id": 0,
"adIndex": -1
}]
嘗試這個 ,
try {
JSONArray array=new JSONArray(res);
if (array.length()>0){
for (int i=0;i<array.length();i++){
JSONObject object1=array.getJSONObject(i);
JSONObject object2=object1.getJSONObject("data");
// do this for your needed objects
if (object2.has("icon")){
Log.d("icon",object2.getString("icon"));
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.