需要帮助从Javascript对象中提取数据

Need help to extract data from Javascript object?

本文关键字:提取 数据 对象 Javascript 帮助      更新时间:2023-09-26

你好,我有这个数据:

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, City Name,然后另一个循环获取姓名,地址和电话。数据格式不正确,我不知道如何修复。

我很感激你的帮助。谢谢你

你的括号关闭了,使得这不是一个有效的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.

中删除。