簡體   English   中英

解析json中的對象數組

[英]Parse an array of object in the json

我有一個以下json對象,我可以獲取plistDatepcategory ,但是我想知道如何解析以下json中的每個image對象。

這是我到目前為止所擁有的

obj = new JSONObject(jsonObject);
listImages = obj.optString("images");

jsonObject

{
    "plistDate": "2016-02-19 22:02:41",
    "pcategory": "Kategori seciniz",
    "images": {
        "pimagePath": "products/138_1455940961.jpg",
        "pimagePath2": "products/138_1455940961_2.jpg",
        "pimagePath3": "products/138_1455940961_3.jpg",
        "pimagePath4": "products/138_1455940961_4.jpg",
        "pimagePath5": "products/138_1455940961_5.jpg"
    }
}

images是內部對象,因此您必須像這樣檢索它

    JSONObject  obj = new JSONObject("you jsin String");
    String pcategory = obj.getString("pcategory");
    String plistDate = obj.getString("plistDate");

    JSONObject images_JsonObject =  obj.getJSONObject("images");
    String pimagePath = images_JsonObject.getString("pimagePath");
    String pimagePath2 = images_JsonObject.getString("pimagePath2");
    String pimagePath3 = images_JsonObject.getString("pimagePath3");
    String pimagePath4 = images_JsonObject.getString("pimagePath4");
    String pimagePath5 = images_JsonObject.getString("pimagePath5");

更新資料

        JSONObject images_JsonObject =  obj.getJSONObject("images");

        Iterator<String> stringIterable =  images_JsonObject.keys();
        HashMap<String, String> hashMap = new HashMap<>();
        ArrayList<String> list = new ArrayList<>();            

        while (stringIterable.hasNext()){
            String key = stringIterable.next();
            hashMap.put(key, images_JsonObject.getString(key));
            list.add(images_JsonObject.getString(key));
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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