gpt4 book ai didi

javascript - 如何检索 JSON 对象然后将其存储到常规 javascript 对象中?

转载 作者:行者123 更新时间:2023-12-03 06:40:51 26 4
gpt4 key购买 nike

我在 json 格式的链接上有这个,我必须检索它

    {"vehicles":[{"name":"motorcycle","wheels":2,"maxCapacity":2,"currentPassengers":1,"maxSpeed":"260 km/h"},{"name":"car","wheels":4,"maxCapacity":4,"currentPassengers":3,"maxSpeed":"220 km/h"},{"name":"aeroplane","wheels":18,"maxCapacity":416,"currentPassengers":215,"maxSpeed":"920 km/h"}]}

将其存储到常规 JavaScript 对象中。

最佳答案

var obj = JSON.parse({"vehicles":[{"name":"motorcycle","wheels":2,"maxCapacity":2,"currentPassengers":1,"maxSpeed":"260 km/h"},{"name":"car","wheels":4,"maxCapacity":4,"currentPassengers":3,"maxSpeed":"220 km/h"},{"name":"aeroplane","wheels":18,"maxCapacity":416,"currentPassengers":215,"maxSpeed":"920 km/h"}]})

然后您可以使用 as obj.vehicles 来访问车辆。

关于javascript - 如何检索 JSON 对象然后将其存储到常规 javascript 对象中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37970042/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com