让某些浏览器支持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)); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。