我在互联网上搜索过,但我无法解析服务器的响应,将值存储在数组数组中,并将其显示在列表视图中。
{"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 :(得分: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
传递给其他活动并将其添加到列表视图。