【发布时间】:2020-01-23 06:17:56
【问题描述】:
Array [
Object {
"resultlist": Array [
Object {
"img": "https://www.act.com/image/cache/catalog/new%20thumbnails/Mifa%20A1BlacjkThumbnail-600x600.jpg",
"name": "Mifa F1",
"product_id": 87,
"type": "product",
},
Object {
"category_id": 20,
"img": "https://www.achhacart.com/image/catalog/cmsblock/hgb5.png",
"name": "Earphone",
"type": "category",
},
Object {
"img": "https://www.achhacart.com/image/catalog/cmsblock/air.gif",
"name": "Air Purifier",
"product_id": 87,
"type": "product",
},
Object {
"img": "https://www.achhacart.com/image/catalog/cmsblock/Powerbank10.jpg",
"name": "Powerbank",
"product_id": 87,
"type": "product",
},
],
"sort_order": 0,
"status": true,
"type": "product",
},
Object {
"img": "https://www.act.com/image/catalog/cmsblock/Powerbank10.jpg",
"product_id": 187,
"sort_order": 1,
"status": true,
"type": "middleimage",
},
Object {
"resultlist": Array [
Object {
"img": "https://www.act.com/image/cache/catalog/new%20thumbnails/Mifa%20A1BlacjkThumbnail-600x600.jpg",
"name": "Mifa A1 Black",
"product_id": 87,
"type": "product",
},
Object {
"category_id": 20,
"img": "https://www.act.com/image/catalog/cmsblock/hgb5.png",
"name": "Earphones",
"type": "category",
},
Object {
"img": "https://www.act.com/image/catalog/cmsblock/air.gif",
"name": "Air Purifiers",
"product_id": 87,
"type": "product",
},
Object {
"img": "https://www.act.com/image/catalog/cmsblock/Powerbank10.jpg",
"name": "Powerbanks",
"product_id": 87,
"type": "product",
},
],
"sort_order": 2,
"status": true,
"type": "product",
},
Object {
"resultlist": Array [
Object {
"image": "https://www.act.com/simage/catalog/1AA/WeChatImage_20191228151402.jpg",
"link": "",
"title": "slider1",
},
Object {
"image": "https://www.act.com/staging-achhamall.com/image/catalog/1accc/WeChatImage_20191231125513.jpg",
"link": "",
"title": "slider2",
},
],
"sort_order": 3,
"status": true,
"type": "slider",
},
]
这是我的 json 响应,我想用数组对象获取我的所有响应对象,我尝试过:-
{data.map((item, i) =>
<View>
<Text key={i}>{item.type}</Text>
{
item.resultlist.map((sub,index)=>
<Text key={index}>sub.name</Text>
)}
</View>
)}
使用项目然后在内部我使用带有索引的子
但随后错误显示
undefined is not an object (evaluating 'item.resultlist.map')
如何获取此嵌套数组对象或我的响应 json 有问题,请建议我在哪里出错? 主要是当我尝试使用
获取数组对象中的单个对象时let products = responseJson.response[0].resultlist[3];
然后使用控制台我只能获取单个对象,但是当使用此映射函数来获取时,它是未定义的
【问题讨论】:
标签: arrays react-native