什么是最好的JSON JavaScript polyfill [英] Whats the best JSON JavaScript polyfill

查看:204
本文介绍了什么是最好的JSON JavaScript polyfill的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找可以在正在编写的某些JavaScript中使用的JSON polyfill(在较旧的浏览器中支持JSON).我发现并发现JSON2和JSON3非常受欢迎,而且我读过JSON3意味着可以替代JSON2,但是我想知道这些是否是最好的polyfill?

I am looking for a JSON polyfill (for JSON support in older browsers) that I can use in some JavaScript I'm writing. I've looked and found JSON2 and JSON3 are quite popular and I've read that JSON3 is meant to be a drop in replacement for JSON2 but I was wondering if these are the best polyfills out there?

我对JSON3的唯一问题是,当我在JSON3库上运行google闭包lint检查时,它抱怨for循环未定义主体: If this if/for/while really shouldn't have a body, use {}

The only problem I have with JSON3 is that when I run the google closure lint checks over the JSON3 library it complains about for loops not defining a body: If this if/for/while really shouldn't have a body, use {}

如果js-lint显示警告这一事实使我无法使用此polyfill,因为当我编译我的库时,它看起来像我的库存在这些问题,因为我将其打包在一起以简化下载过程我的JavaScript.

Should the fact that the js-lint is showing warnings put me off using this polyfill as when I compile my library it makes it look like my library has these problems as I'm packaging it up together to simplify it for people downloading my javascript.

推荐答案

您可以使用Douglas Crockford提供的JSON库.

You can use the JSON library provided by Douglas Crockford.

https://github.com/douglascrockford/JSON-js .

您可以无条件包含它,并且仅当尚未定义时才添加JSON.parse和JSON.stringify.

You can include it unconditionally, and it adds JSON.parse and JSON.stringify only if there isn't one defined yet.

这篇关于什么是最好的JSON JavaScript polyfill的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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