Whats the best JSON JavaScript polyfill

醉酒当歌 提交于 2019-12-02 15:40:59

问题


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?

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 {}

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.


回答1:


You can use the JSON library provided by Douglas Crockford.

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

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



来源:https://stackoverflow.com/questions/35335053/whats-the-best-json-javascript-polyfill

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!