Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1173065
  • 博文数量: 272
  • 博客积分: 3899
  • 博客等级: 中校
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2012-06-15 14:53
文章分类

全部博文(272)

文章存档

2012年(272)

分类: Python/Ruby

2012-06-26 13:09:35

native JSON API 是 ECMAScript 3.1 里的新标准,目前 Firefox 3.1 和 IE 8 RC1 已经支持这个API。

这是浏览器内置的,所以解析json的速度会更快。同时保证了安全性。

在我的 Firefox 3.1 中测试如下代码:


上面这段代码在 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.

resource: http://blog.mozilla.com/webdev/2009/02/12/native-json-in-firefox-31/
阅读(920) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~