我想解析这个api响应来获取图像网址,我发现它实际上有点令人困惑,因为我是apis的新手。
{
"id": "123",
"item": [
{
"picture": {
"type_id": "2",
"url": [
"./img.jpg"
],
"is_in_description": 0,
"gallery": {
"url": "",
"url_id": ""
},
"layout_id": "2",
"variation_name": ""
},
"lister_id": "12345"
}
]
}
这是我获取api的代码,任何人都可以帮助我
fetch(url2,{
method: 'GET'
})
.then((response)=> response.json())
.then((responseJson) => {
const newImg = responseJson.item.map( => {
return{
const img =
};
})
const newState = Object.assign({}, this.state, {
items: newItems
});
console.log(newState);
this.setState(newState);
})
.catch((error) => {
console.log(error)
});
使用map
方法进行解析
var x = {
"id": "123",
"item": [
{
"picture": {
"type_id": "2",
"url": [
"./img.jpg"
],
"is_in_description": 0,
"gallery": {
"url": "",
"url_id": ""
},
"layout_id": "2",
"variation_name": ""
},
"lister_id": "12345"
}
]
}
x.item.map(data=>{console.log(data.picture.url)}) //hope you need the url object