2017-06-15 19 views
-1

我已經在互聯網上搜索了所有內容,但是我無法解析我的服務器響應,將值存儲在數組數組中並將其顯示在列表視圖中。如何將數據從服務器存儲到數組中並將其顯示在listview android?

{"bannerImages": [ 
{ 
    "bannerImage": "dev.beacon.interrait.com/resources/deal-1.jpg", 
    "id": 1 
} ], "departmentAndCategory": [ 
{ 
    "departmentName": "Apparels", 
    "departmentDescription": "Apparels", 
    "categoryList": [], 
    "storeId": null, 
    "id": 1 
}, 
{ 
    "departmentName": "Footwear", 
    "departmentDescription": "footwear for men,women and kids", 
    "categoryList": [ 
    { 
     "categoryId": 4, 
     "departmentId": 10, 
     "categoryName": "Footwear", 
     "categoryDescription": "Footwear for men,women and kids", 
     "parentCategoryId": null 
    }, 
    { 
     "categoryId": 2, 
     "departmentId": 10, 
     "categoryName": "Vehicles", 
     "categoryDescription": "Two and Four wheelers", 
     "parentCategoryId": null 
    } 
    ], 
    "storeId": null, 
    "id": 10 
}, 
{ 
    "departmentName": "Appliances", 
    "departmentDescription": "TV,Washing Machines,Refrigerators etc.", 
    "categoryList": [ 
    { 
     "categoryId": 5, 
     "departmentId": 11, 
     "categoryName": "Appliances", 
     "categoryDescription": "Appliances for home like TV,Washing Machines,Refrigerators etc.", 
     "parentCategoryId": null 
    }, 
    { 
     "categoryId": 1, 
     "departmentId": 11, 
     "categoryName": "Vehicles", 
     "categoryDescription": "Two and Four wheelers", 
     "parentCategoryId": null 
    }, 
    { 
     "categoryId": 12, 
     "departmentId": 11, 
     "categoryName": "testing department", 
     "categoryDescription": "testing", 
     "parentCategoryId": null 
    }, 
    { 
     "categoryId": 13, 
     "departmentId": 11, 
     "categoryName": "2 wheelers", 
     "categoryDescription": "2 wheelers", 
     "parentCategoryId": null 
    } 
    ], 
    "storeId": null, 
    "id": 11 
}, 
{ 
    "departmentName": "Electronics", 
    "departmentDescription": "Mobile Phones,Routers etc.", 
    "categoryList": [ 
    { 
     "categoryId": 6, 
     "departmentId": 12, 
     "categoryName": "Electronics", 
     "categoryDescription": "Electrnocs for personal use like Mobile Phones,Routers etc.", 
     "parentCategoryId": null 
    } 
    ], 
    "storeId": null, 
    "id": 12 
}, 
{ 
    "departmentName": "Home & Furniture", 
    "departmentDescription": "All your Home & Furniture needs", 
    "categoryList": [], 
    "storeId": null, 
    "id": 2 
}, 
{ 
    "departmentName": "apparels", 
    "departmentDescription": "apparels", 
    "categoryList": [], 
    "storeId": null, 
    "id": 15 
}, 
{ 
    "departmentName": "Levi`s Tshirt", 
    "departmentDescription": "Levi`s Tshirt", 
    "categoryList": [], 
    "storeId": null, 
    "id": 16 
}, 
{ 
    "departmentName": "testing update", 
    "departmentDescription": "testing update", 
    "categoryList": [], 
    "storeId": null, 
    "id": 14 
}],"productsAndDeals": [ 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "A good fabric from levis", 
    "productPrice": 2000, 
    "productInStock": 7, 
    "totalSaving": null, 
    "productName": "Levis T-shirt", 
    "title": "Clothes", 
    "id": 1 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "", 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "best blue jeans", 
    "productPrice": 1000, 
    "productInStock": 15, 
    "totalSaving": null, 
    "productName": "skin-fit", 
    "title": "Jeans", 
    "id": 2 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "", 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "", 
    "productPrice": 1000, 
    "productInStock": 12, 
    "totalSaving": null, 
    "productName": "Aman", 
    "title": "Tshirt", 
    "id": 6 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product not in stock", 
    "dealResponseVO": null, 
    "productDescription": "New T-shirt collection", 
    "productPrice": 599, 
    "productInStock": 0, 
    "totalSaving": null, 
    "productName": "T-shirts for Men", 
    "title": "T-shirts", 
    "id": 7 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "askkkdd", 
    "productPrice": null, 
    "productInStock": 1, 
    "totalSaving": null, 
    "productName": "abvgc", 
    "title": "dddrr", 
    "id": 19 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "askkkdd", 
    "productPrice": null, 
    "productInStock": 1, 
    "totalSaving": null, 
    "productName": "top", 
    "title": "dddrr", 
    "id": 20 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "askkkdfffd", 
    "productPrice": null, 
    "productInStock": 1, 
    "totalSaving": null, 
    "productName": "topsss", 
    "title": "dddrr", 
    "id": 21 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "askkkdfffd", 
    "productPrice": null, 
    "productInStock": 1, 
    "totalSaving": null, 
    "productName": "topsss", 
    "title": "dddrr", 
    "id": 22 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "sample", 
    "productPrice": null, 
    "productInStock": 10, 
    "totalSaving": null, 
    "productName": "sample", 
    "title": "Product", 
    "id": 23 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "sample", 
    "productPrice": null, 
    "productInStock": 10, 
    "totalSaving": null, 
    "productName": "sample", 
    "title": "Product", 
    "id": 24 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "sample", 
    "productPrice": null, 
    "productInStock": 10, 
    "totalSaving": null, 
    "productName": "sample", 
    "title": "Product", 
    "id": 25 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "smartphones", 
    "productPrice": null, 
    "productInStock": 1, 
    "totalSaving": null, 
    "productName": "mobile", 
    "title": "dddrr", 
    "id": 30 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": null, 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "fresh apples from farm", 
    "productPrice": 150, 
    "productInStock": 90, 
    "totalSaving": null, 
    "productName": "Apples", 
    "title": "Red apples", 
    "id": 31 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "slippin.jpeg", 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "Slip Ons", 
    "productPrice": 210, 
    "productInStock": 45, 
    "totalSaving": null, 
    "productName": "slippers and jackets", 
    "title": "Liberty slippes", 
    "id": 110 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "", 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "glucone D", 
    "productPrice": 60, 
    "productInStock": 123, 
    "totalSaving": null, 
    "productName": "glucose", 
    "title": "Glucose for health", 
    "id": 117 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "new.jpeg", 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "rugged jackets", 
    "productPrice": 210, 
    "productInStock": 45, 
    "totalSaving": null, 
    "productName": "jackets", 
    "title": "Liberty slippes", 
    "id": 121 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "", 
    "productPriceAfterDiscount": null, 
    "imageName": "--", 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "pens,pencil", 
    "productPrice": 10, 
    "productInStock": 100, 
    "totalSaving": null, 
    "productName": "Stationary", 
    "title": "--", 
    "id": 127 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "p.jpeg", 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "cricket bats", 
    "productPrice": 500, 
    "productInStock": 20, 
    "totalSaving": null, 
    "productName": "bat", 
    "title": "games for kids", 
    "id": 128 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "p.jpeg", 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "cricket bats", 
    "productPrice": 500, 
    "productInStock": 20, 
    "totalSaving": null, 
    "productName": "ball", 
    "title": "games for kids", 
    "id": 130 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "p.jpeg", 
    "productPriceAfterDiscount": null, 
    "imageName": "a.jpeg", 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "cricket bats", 
    "productPrice": 500, 
    "productInStock": 20, 
    "totalSaving": null, 
    "productName": "sports", 
    "title": "games for kids", 
    "id": 131 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "ping.jpeg", 
    "productPriceAfterDiscount": null, 
    "imageName": "newi.jpeg", 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "axe", 
    "productPrice": 500, 
    "productInStock": 20, 
    "totalSaving": null, 
    "productName": "garden", 
    "title": "-", 
    "id": 132 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "a.jpg", 
    "productPriceAfterDiscount": null, 
    "imageName": "front_view", 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "--", 
    "productPrice": 50, 
    "productInStock": 12, 
    "totalSaving": null, 
    "productName": "--", 
    "title": "--", 
    "id": 133 
}, 
{ 
    "discountPercentage": null, 
    "smallImage": "", 
    "productPriceAfterDiscount": null, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "best blue jeans", 
    "productPrice": 1300, 
    "productInStock": 15, 
    "totalSaving": null, 
    "productName": "bell-bottoms", 
    "title": "Jeans", 
    "id": 3 
}, 
{ 
    "discountPercentage": 50, 
    "smallImage": "", 
    "productPriceAfterDiscount": 550, 
    "imageName": null, 
    "productAvailability": "Product is available", 
    "dealResponseVO": null, 
    "productDescription": "best blue jeans", 
    "productPrice": 1100, 
    "productInStock": 15, 
    "totalSaving": 550, 
    "productName": "curve-jeans", 
    "title": "Jeans", 
    "id": 4 
} ]} 

這是在這我想在一個列表視圖中顯示部門的名稱,並通過點擊部門名稱的json響應,其所屬類別應在列表視圖另一個屏幕打開。

+0

使用此網站來生成模型類:http://www.jsonschema2pojo.org/ –

+0

使用此參考網站了解更多詳情:http://androidcss.com/android/fetch-json-data-android/ –

+0

i我得到我的迴應,但我想存儲部門名稱在一個數組中,並通過點擊部門名稱相應的類別列表應該打開 – aman

回答

1

獲取一個JSONArray你的部門類別這樣

JSONArray jaDeptCategory = your_main_obj.get("departmentAndCategory"); 

,然後你可以使用這個JSONArray爲您的列表視圖和顯示部門名稱再見個人獲得的obj這樣

JSONObject joDept = jaDeptCategory.getJSONObject(0)//use for loop for iterate (you can use any loop for iteration eg: while loop) 

之後您可以在單擊列表視圖後將您的類別列表傳遞給另一個活動。

JSONArray joCategoryList = joDept.get("categoryList"); 

將您的joCategoryList傳遞給其他人並將其添加到列表查看中。

+0

你能解釋它,以及如何通過點擊部門名稱來調用相應的類別數組? – aman

+0

使用onItemClickListner你會得到你的部門被點擊的位置,然後得到joDept = jaDeptCategory.getJSONObject(position),這會給你各自的categoryList –

相關問題