function decode(json){
return eval("("+json+")");
} var obj='{id:\"1\",text:\"测试\"}';
alert(decode(obj));
for(var x in decode(obj)){
alert(x+"|"+decode(obj)[x]);
}decode函数的作用是把一个规定格式的字符串转换为对象,我想问下eval("("+json+")")的原理,如“(”的作用?
return eval("("+json+")");
} var obj='{id:\"1\",text:\"测试\"}';
alert(decode(obj));
for(var x in decode(obj)){
alert(x+"|"+decode(obj)[x]);
}decode函数的作用是把一个规定格式的字符串转换为对象,我想问下eval("("+json+")")的原理,如“(”的作用?
var a = "{showmsg:function(o){alert(o)}}";
var b = eval("("+a+")");
b.showmsg('hello,world!');(function(){alert('这里的括号返回一个匿名对象,只有返回对象才能继续操作!')})();
</script>