javascript 常用函数

  1. JSON解析函数

      

window.JSON = {};
JSON.parse = function(text, reviver) {
			function walk(e, t) {
				var n, r, i = e[t];
				if (i && typeof i == "object") for (n in i) Object.hasOwnProperty.call(i, n) && (r = walk(i, n), r !== undefined ? i[n] = r : delete i[n]);
				return reviver.call(e, t, i)
			}
			var j;
			text = String(text), cx.lastIndex = 0, cx.test(text) && (text = text.replace(cx, function(e) {
				return "\\u" + ("0000" + e.charCodeAt(0).toString(16)).slice(-4)
			}));
			if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) return j = eval("(" + text + ")"), typeof reviver == "function" ? walk({
				"": j
			}, "") : j;
			throw new SyntaxError("JSON.parse")
		}

   var data = '{"code":200,"msg":"ok","current_time":"2013-06-15 13:37:49","data":[]}';
    console.log( JSON.parse( data ) );


你可能感兴趣的:(javascript 常用函数)