簡體   English   中英

如何將JsonArray轉換為ArrayList但JsonArray中的JsonObject不是同一結構

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM