jQuery中json对象与json字符串互换
json字符串转json对象:jQuery.parseJSON(jsonStr);
json对象转json字符串:JSON.stringify(jsonObj);
IE中可能对unicode使用“\uXXXX”格式来编码,可以使用如下来解码:
function unicode2Char(str) {
return (str.replace(/\\/g, "%"));
}
也可以用google的json插件
jquery-json:https://code.google.com/p/jquery-json/
var thing ={plugin:'jquery-json', version:2.3};
var encoded = $.toJSON( thing );
// '{"plugin":"jquery-json","version":2.3}'
var name = $.evalJSON( encoded ).plugin;
// "jquery-json"
var version = $.evalJSON(encoded).version;