var jsonstring = '{"name":"axis", "org":"ph4nt0m", "blog":""}';
var ok = JSON.parse(jsonstring); // 浏览器内置的API
alert(ok.blog);
上面这段代码在 IE7 里是通不过的。
用firebug 查看DOM,发现成功 parse 了
使用内置的API,按照mozilla的说法,比使用eval来parse快了将近2.7倍
而且更安全,因为函数不会被解析,只会取里面的属性。原文这么说的: Native JSON parsing in Firefox 3.1 is safer because it does not support objects with functions. Attempting to convert an object with functions into a JSON string will only convert its properties and not its functions. And any malformed JSON string will result in a parse error instead of possible code execution.