数据来源:https://lbs.qq.com/service/webService/webServiceGuide/webServiceDistrict
因为json数据较大,建议使用在线ide,推荐 https://www.sojson.com/runjs.html,运行好后直接在控制台copy
```js
/**
* 转换官方json数据为上手可用数据
* {Array} arr 官方city数据 https://apis.map.qq.com/ws/district/v1/list?key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77
*/
function changeCityData (arr) {
for (let v of arr[0]) {
v['name'] = v.fullname
let cityArrTemp = [...arr[1]].splice(v.cidx[0], (v.cidx[1] - v.cidx[0] + 1))
v['child'] = cityArrTemp
for (let iv of v.child) {
iv['name'] = iv.fullname
if(iv.cidx){
let iAreaArrTemp = [...arr[2]].splice(iv.cidx[0], (iv.cidx[1] - iv.cidx[0] + 1))
iv['child'] = iAreaArrTemp
for (let iiv of iv.child) {
iiv['name'] = iiv.fullname
}
}
}
}
console.log(JSON.stringify(arr[0]))
return arr
}
changeCityData(arr)
```
不错