javascript 常用函数
2013-06-15 13:42
176 查看
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 = r : delete i ); 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 ) );
相关文章推荐
- 20个最常用的javascript方法函数
- javascript 常用的时间函数
- javascript 常用函数
- JavaScript 常用函数
- javascript 常用函数整理
- javascript常用函数!
- JavaScript常用函数
- JavaScript常用工具函数
- 几个常用的JavaScript字符串处理函数 - split()、join()、substring()和indexOf()
- javascript常用函数(2)
- 常用一些Javascript判断函数
- 几个常用的JavaScript字符串处理函数 - split()、join()、substring()和indexOf()
- javascript常用自定义函数
- 常用的JavaScript字符串处理函数及用法
- JavaScript运动基础,常用函数封装
- Javascript里使用Dom操作Xml笔记之常用函数[转]
- javascript常用方法函数收集
- JavaScript常用方法函数汇集
- 7个JavaScript常用函数
- JAVASCRIPT常用函数集合