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