所有主流浏览器都支持 JSON.parse 吗? [英] Is JSON.parse supported by all major browsers?

查看:35
本文介绍了所有主流浏览器都支持 JSON.parse 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

可能的重复:
浏览器原生 JSON 支持 (window.JSON)

具体来说,IE7+、Firefox 2+、Chrome、Safari 是否支持 JSON.parse(...)?

参见:JavaScript 中的 JSON

解决方案

2013(及以后)的答案

<块引用>

所有主流浏览器都支持 JSON.parse 吗?

差不多,是的(来源).甚至 IE8 都有它(前提是您不在 IE7 仿真模式下).如果您需要支持 IE7 及更早版本,请继续阅读.

2011 年的原始答案

不,较旧的浏览器(例如 IE7)大多没有它.(更多:http://caniuse.com/#search=JSON.parse)>

然而,您只需要一个小脚本.JSON 的发明者 Douglas Crockford 在 他的 Github 页面上有不少于三个供您选择.一个>:

使用适合您的东西.:-)

几乎所有主要库(如 jQuery原型YUIClosure任何一个其他人) 也将提供 JSON 解析,尽管在某些情况下它可能只是 eval 的一个薄饰面.

Possible Duplicate:
Browser-native JSON support (window.JSON)

Specifically, is JSON.parse(...) supported by IE7+, Firefox 2+, Chrome, Safari?

See: JSON in JavaScript

解决方案

The answer in 2013 (and later)

Is JSON.parse supported by all major browsers?

Pretty much, yes (source). Even IE8 has it (provided you're not in IE7 emulation mode). If you need to support IE7 and earlier, read on.

The original answer from 2011

No, older browsers (IE7 for instance) mostly don't have it. (More: http://caniuse.com/#search=JSON.parse)

However, just a small script is all you need. The inventor of JSON, Douglas Crockford, has no fewer than three for you to choose from on his Github page:

  • json2.js: Provides both JSON.parse and JSON.stringify. Parsing uses a few regexes to defend against script injection attacks and then passes the result to eval. This isn't generally considered a very good idea.
  • json_parse.js: A recursive-descent parser that doesn't use eval.
  • json_parse_state.js: A state-machine parser that doesn't use eval.

Use what suits you. :-)

Just about any major library (like jQuery, Prototype, YUI, Closure, or any of several others) will also provide JSON parsing, although in some cases it may well be a thin veneer on eval.

这篇关于所有主流浏览器都支持 JSON.parse 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆