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'}]