当前位置:编程学习 > JS >>

json数据与字符串的相互转化

json转成string[需要引用json2.js文件]:
 
var arr=[{id:'id',name:'Spring'},{id:'id2',name:'Jane'}];
 
var str=JSON.stringify(arr);
 
结果:"[{id:'id',name:'Spring'},{id:'id2',name:'Jane'}]"
 
 
 
string转化为json:
 
var str="[{id:'id',name:'Spring'},{id:'id2',name:'Jane'}]";
 
var json=$.parseJSON(str);
 
结果:[{id:'id',name:'Spring'},{id:'id2',name:'Jane'}]
补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,