日期:2014-05-16  浏览次数:20426 次

修改json格式
使用js对json进行操作,{"AreaName":"江苏省","AreaCode":"320000"},{"AreaName":"南京市","AreaCode":"320100"},{"AreaName":"市辖区","AreaCode":"320101"},{"AreaName":"玄武区","AreaCode":"320102"},{"AreaName":"白下区","AreaCode":"320103"},{"AreaName":"秦淮区","AreaCode":"320104"},{"AreaName":"建邺区","AreaCode":"320105"},{"AreaName":"鼓楼区","AreaCode":"320106"},{"AreaName":"下关区","AreaCode":"320107"},{"AreaName":"浦口区","AreaCode":"320111"},{"AreaName":"栖霞区","AreaCode":"320113"},{"AreaName":"雨花台区","AreaCode":"320114"},{"AreaName":"江宁区","AreaCode":"320115"},{"AreaName":"六合区","AreaCode":"320116"},{"AreaName":"溧水县","AreaCode":"320124"},{"AreaName":"高淳县","AreaCode":"320125"}这种样式的数据转换成

{"AreaName":"江苏省","AreaCode":"320000","cityList":[{"AreaName":"南京市","AreaCode":"320100","areaList":[{"AreaName":"市辖区","AreaCode":"320101"},{"AreaName":"玄武区","AreaCode":"320102"},{"AreaName":"白下区","AreaCode":"320103"},{"AreaName":"秦淮区","AreaCode":"320104"},{"AreaName":"建邺区","AreaCode":"320105"},{"AreaName":"鼓楼区","AreaCode":"320106"},{"AreaName":"下关区","AreaCode":"320107"},{"AreaName":"浦口区","AreaCode":"320111"},{"AreaName":"栖霞区","AreaCode":"320113"},{"AreaName":"雨花台区","AreaCode":"320114"},{"AreaName":"江宁区","AreaCode":"320115"},{"AreaName":"六合区","AreaCode":"320116"},{"AreaName":"溧水县","AreaCode":"320124"},{"AreaName":"高淳县","AreaCode":"320125"}]}]}
这种形式的,用js怎么实现??大神求帮助
JSON JavaScript

------解决方案--------------------
引用:
写的有点恶心,如果有问题我再优化一下。

var citys = [
    {"AreaName":"江苏省","AreaCode":"320000"},
    {"AreaName":"南京市","AreaCode":"320100"},
    {"AreaName":"市辖区","AreaCode":"320101"},
    {"AreaName":"玄武区","AreaCode":"320102"},
    {"AreaName":"白下区","AreaCode":"320103"},
    {"AreaName":"秦淮区","AreaCode":"320104"},
    {"AreaName":"建邺区","AreaCode":"320105"},
    {"AreaName":"鼓楼区","AreaCode":"320106"},
    {"AreaName":"下关区","AreaCode":"320107"},
    {"AreaName":"浦口区","AreaCode":"320111"},
    {"AreaName":"栖霞区","AreaCode":"320113"},
    {"AreaName":"雨花台区","AreaCode":"320114"},
    {"AreaName":"江宁区","AreaCode":"320115"},