2017-06-15 2 views
-1

Ich habe überall im Internet gesucht, aber ich bin nicht in der Lage, meine Antwort vom Server zu analysieren, um Werte in Arrays von Arrays zu speichern und sie in einer Listenansicht anzuzeigen.Wie speichert man Daten vom Server in Arrays von Arrays und zeigt sie in einem Listenansicht Android an?

{"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 
} ]} 

Dies ist meine Json Antwort in dieser ich will Abteilungsnamen in einer Listenansicht und durch einen Klick auf den Abteilungsnamen, ihre jeweiligen Kategorien in einem anderen Bildschirm in Listenansicht öffnen sollten angezeigt werden soll.

+0

Verwenden Sie diese Website, um Modellklasse zu generieren: http://www.jsonschema2pojo.org/ –

+0

Verwenden Sie diese Referenzsite für weitere Details: http://androidcss.com/android/fetch-json-data-android/ –

+0

i bekomme ich meine Antwort, aber ich möchte Abteilungsname in einem Array speichern und durch Klicken auf Abteilungsname jeweiligen Kategorie Liste geöffnet werden sollte – aman

Antwort

1

Holen Sie sich Ihre Abteilung Kategorie in einer JSONArray wie diese

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

Und dann können Sie diese JSONArray verwenden für Ihre Listenansicht und Anzeige Abteilungsnamen bye immer einzelne obj wie dieses

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

Danach Sie können Ihre Kategorieliste in einer anderen Aktivität übergeben, nachdem Sie auf Listenansicht geklickt haben.

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

Übergeben Sie Ihre joCategoryList in einer anderen Aktivität und fügen Sie das zu listview hinzu.

+0

können Sie es bitte erklären und wie Sie das entsprechende Kategorie-Array aufrufen, indem Sie auf den Abteilungsnamen klicken? – aman

+0

OnItemClickListner verwenden Sie erhalten eine Position, auf die Ihre Abteilung geklickt wird, und erhalten dann joDept = jaDeptCategory.getJSONObject (position) und erhalten die entsprechende categoryList –

Verwandte Themen