js 把json字符串转为json对象

Posted enych

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js 把json字符串转为json对象相关的知识,希望对你有一定的参考价值。


   <input type="hidden" name="data" id="data" value=‘[{"name":"北京","value":1,"children":[{"name":"北京市1","value":12,"children":[{"name":"朝阳区1","value":13,"children":[]},{"name":"朝阳区2","value":14,"children":[]},{"name":"朝阳区3","value":15,"children":[]},{"name":"朝阳区4","value":16,"children":[]}]},{"name":"北京市2","value":17,"children":[]},{"name":"北京市3","value":18,"children":[]},{"name":"北京市4","value":19,"children":[]}]},{"name":"天津","value":2,"children":[{"name":"天津市1","value":51,"children":[]}]}]‘ />
[{},{}] 正确
[{},{},] 转json对象是报错 (直接写数组不报错)
var
Jsondata = $("#data")[0].defaultValue;
var jsonobj = JSON.parse(Jsondata); layui.formSelects.data(‘select15‘, ‘local‘, { arr: jsonobj, linkage: true ////开启联动模式 } );

 






以上是关于js 把json字符串转为json对象的主要内容,如果未能解决你的问题,请参考以下文章

JS对象如何转为json格式字符串

java 把json对象转换成json字符串

如何把js字符串转化为对象?

怎么把json字符串转成数组对象

js超过18位最后转为0是啥情况

JS基础(十) 将字符串转为对象