json - 无法提取 json 响应
问题描述
我正在尝试提取 JSON 响应。当我尝试访问 json 数组中的对象时,它返回 undefined
weather= [{"id":711,"main":"Smoke","description":"smoke","icon":"50d"}]
var x=JSON.stringify(weather)
x[0].main= returns =>undefined
解决方案
您可以简单地使用Array#map OR Array#forEach函数来获取所有 JSON 数据。您不需要在JSON.stringify
您的回复中使用。
演示:
let weather = [{
"id": 711,
"main": "Smoke",
"description": "smoke",
"icon": "50d"
}]
weather.map(function(x) {
console.log(x.id) //711
console.log(x.main) //Smoke
console.log(x.description) //smoke
console.log(x.icon) //50d
})
推荐阅读
- xml - 空手道框架根据条件建议填充 XML 列表
- git - git中的壁球提交
- amazon-web-services - 如何根据 Nuxt 的环境使用不同的 URL?
- c# - 如何在其他开发环境中应用 EF 迁移?
- reactjs - 使用下一个 js 运行反应应用程序时出错
- python-3.x - 使用 plt.fill_between 和 plt.subplot
- python - 我需要从列表列表中制作字典
- spring - 将相关文档保存在 Mongo Reactive 但不在同一个集合中
- javascript - 如何用 Javascript 中的异步请求的结果填充对象的属性?
- excel - 使用 VBScript 将 Excel 工作表的(部分)范围导出为 CSV