【发布时间】:2018-05-20 13:09:01
【问题描述】:
我在提取来自 API 的 Json 数据时遇到问题。
请帮我改正我的错误。
JSON
[
{
"flagshipId":"18",
"BanquetValues":"<p>xzxzxczx<\/p>\n",
"FloorPlan":"[{\"id\":1,\"fileName\":\"megarugas-15243406450731525866511-1.jpg\",\"ifActive\":\"1\"},{\"id\":2,\"fileName\":\"megarugas-15243406467351525866513-2.jpg\",\"ifActive\":\"1\"},{\"id\":3,\"fileName\":\"megarugas-15244876214221526013635-3.jpg\",\"ifActive\":\"1\"}]",
"ChildDescription":"[{\"id\":1,\"childName\":\"Ceremony 1 @ Megarugas\",\"description\":\"xczxcxvx\"}]",
"RestaurantId":"695"
}
]
我想将 FloorPlan 数组中的文件名显示到我的轮播中。
JSX
render()
{
var banquetImg = this.props.IMG_BASE + this.props.RESTAURANT_BANNER_PATH
return (
<div className="photosSection">
{
this.props.banquetImageList.length != 0
?
<div className="body">
<div className="row">
<Carousel showArrows={true} >
{this.props.banquetImageList.map((row, i) =>
<div key={row.RestaurantAttachmentId} className={"row"}>
<img src={banquetImg + row.FileName} key={row.RestaurantAttachmentId}/>
<p className="get-final-price">Get Final Price</p>
</div>
)}
</Carousel>
</div>
</div>
:
""
}
</div>
);
}
【问题讨论】:
-
如果
json_object[0].FloorPlan是序列化对象,可以使用JSON.parse(json_string_here)将其转换为json。 -
@Al.G.感谢您的答复。你能帮我这样做吗?我无法修复它。
-
是的,当然。写
JSON.parse(json_object[0].FloorPlan),你会得到所需的数组。 -
@Al.G.它返回 Uncaught TypeError: Cannot read property 'FloorPlan' of undefined
标签: arrays json reactjs arraylist carousel