gpt4 book ai didi

javascript - 需要帮助从 Javascript 对象提取数据吗?

转载 作者:行者123 更新时间:2023-11-27 23:52:43 25 4
gpt4 key购买 nike

您好,我有以下数据:

var data={
"city_id": "2",
"dist": "2",
"City Name 1": [
{
"id": 1,
"name": "name 1",
"address": "address 1",
"tel": "tel 1",
"Radio": "0",
"surgery": "0"
},
{
"id": 2,
"name": "name 2",
"address": "address 2",
"tel": "tel 2",
"Radio": "0",
"surgery": "0"
}
],{
"city_id": "2",
"dist": "2",
"City Name 2": [
{
"id": 1,
"name": "name 1",
"address": "address 1",
"tel": "tel 1",
"Radio": "0",
"surgery": "0"
},
{
"id": 2,
"name": "name 2",
"address": "address 2",
"tel": "tel 2",
"Radio": "0",
"surgery": "0"
}
]
}
};

我想循环遍历此 JSON 数据以提取 City_id、dist_id、城市名称,然后另一个循环以获取姓名、地址和电话。数据格式不正确,不知道如何修复。

感谢您的帮助。谢谢

最佳答案

你的括号关闭了,这使得它不是一个有效的 json。

var data={ //------------------------------------open
"city_id": "2",
"dist": "2",
"City Name 1": [
{//----------------------open
"id": 1,
"name": "name 1",
"address": "address 1",
"tel": "tel 1",
"Radio": "0",
"surgery": "0"
},//----------------------close
{//-----------------------open
"id": 2,
"name": "name 2",
"address": "address 2",
"tel": "tel 2",
"Radio": "0",
"surgery": "0"
}//----------------------close
],{//----------------------------------open (problem is here. There is nothing index this object}
"city_id": "2",
"dist": "2",
"City Name 2": [
{//-----------------------open
"id": 1,
"name": "name 1",
"address": "address 1",
"tel": "tel 1",
"Radio": "0",
"surgery": "0"
},//----------------------close
{//-----------------------open
"id": 2,
"name": "name 2",
"address": "address 2",
"tel": "tel 2",
"Radio": "0",
"surgery": "0"
}//----------------------close
]
}//----------------------------------close
}; //------------------------------------------------close

该位需要位于数组中或从 json 中删除。

关于javascript - 需要帮助从 Javascript 对象提取数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32574925/

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