首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

js中怎么把json数组转成json对象

2013-09-06 
js中如何把json数组转成json对象JSONArray jsonarray JSONArray.fromObject(comList) //ListString s

js中如何把json数组转成json对象

JSONArray jsonarray = JSONArray.fromObject(comList); 
//List<String> strList = new ArrayList<String>();
pWriter.print(jsonarray);
ajax到后台获得的json数组

var json = 
[
    {
          "cId":"0011",
          "cName":"aaa",
          "list":[
                 {"dId":"0001","dName":"监查审计部","deptList":[]},
                 {"dId":"Dpt0002","dName":"财务部","deptList":[]
                 ]
     },
    {
          "cId":"0001",
          "cName":"bbb",
          "list":[
                 ]
     }
]


想把他转成json对象,一定要是json对象
var newJson = {
                 id:"0011",
                 name:"aaa",
                 children:[
                            {
                              id:"0001",
                              name:"监查审计部",
                              children:[]
                             },
                            {
                               id:"Dpt0002",


                               name:"财务部",
                               children:[]
                             }
                           ] 
             },
            {
                id:"0001",
                name:"bbb",
                children:[] 
             }


就是json数组 转换成json对象,必须是
[解决办法]
可以,把这个数组赋值为一个json对象的value
[解决办法]
eval   ...

热点排行