让某些浏览器支持JSON.stringify
function forIn(obj, handler) { for (var i in obj) { if (obj.hasOwnProperty(i)) { handler(i, obj[i]); } } } function each(arr, handler) { for (var i = 0, len = arr.length; i < len; i += 1) { handler(i, arr[i]); } } if (!JSON) { JSON = {}; } if (!JSON.parse) { JSON.parse = function (json) { return eval('1,' + json) }; } if (!JSON.stringify) { (function (JSON) { var arr = '[object Array]', obj = '[object Object]'; JSON.stringify = function (json) { var t = ''; var m = Object.prototype.toString.call(json); if (m == arr) { t = ArrPartten(json); } else if (m == obj) { t = ObjectJson(json); } else { t = json; } return t; } function ObjectParse() { var t = '{'; forIn(json, function (i, ele) { var m = Object.prototype.toString.call(ele); if (m == arr) { t += i + ':' + ArrPartten(ele) + ','; } else if (m == obj) { t += i + ':' + ObjectJson(ele) + ','; } else { t += i + ':' + ele + ','; } }); if (t.length != 1) { t = t.substring(0, t.length - 1); } return t + '}'; } function ArrayParse() { var t = '['; each(json, function (i, ele) { var m = Object.prototype.toString.call(ele); if (m == arr) { t += ArrPartten(ele) + ','; } else if (m == obj) { t += ObjectJson(ele) + ','; } else { t += ele + ','; } }); if (json.length > 0) { t = t.substring(0, t.length - 1); } return t + ']'; } }(JSON)); }