日期:2014-05-16 浏览次数:20376 次
var jsonStr="{a:1}"; var jsonObj = eval("("+jsonStr+")");?
parseJSON:function( data ) { if ( typeof data !== "string" || !data ) { return null; } // Make sure leading/trailing whitespace is removed (IE can't handle it) data = jQuery.trim( data ); // Make sure the incoming data is actual JSON // Logic borrowed from http://json.org/json2.js if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@") .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]") .replace(/(?:^|:|,)(?:\s*\[)+/g, "")) ) { // Try to use the native JSON parser first return window.JSON && window.JSON.parse ? window.JSON.parse( data ) : (new Function("return " + data))(); } else { jQuery.error( "Invalid JSON: " + data ); } }?
(new Function("return " + data))();?
function test() { var jsonStr ="{"; for(var i=0;i<10000;i++){ jsonStr+="a"+i+":"+i+","; } jsonStr = jsonStr.substring(0,jsonStr.length-1); jsonStr+="}"; var date = new Date(); var start = date.getTime(); var boj = (new Function("return "+jsonStr ))(); //var boj = eval("("+jsonStr+")"); var date1 = new Date(); alert(date1.getTime()-start); }?