开发者

How do I use JSON in older browsers?

开发者 https://www.devze.com 2023-01-30 02:48 出处:网络
In javascript, I want to use JSON.stringify. But some (older) browsers do not recognize JSON as a defined object. Is there a javascript file that I can include that defines JSON, and all it\'s awesome

In javascript, I want to use JSON.stringify. But some (older) browsers do not recognize JSON as a defined object. Is there a javascript file that I can include that defines JSON, and all it's awesome functionality, for browsers that do not natively support JSON?

I should note that I'm referring to a specifically defined JSON object, rather than t开发者_开发技巧he more general concept of javascript object notation.


Douglas Crockford (the inventor of JSON) provides json2.js, an efficient JSON "parser" that doesn't actually parse JSON; it uses regular expressions to sanitise JSON before passing it to eval, and falls back on native JSON support if the browser has it.

He also provides a more conventional recursive-descent parser and a state-machine-based parser in the same repo.

0

精彩评论

暂无评论...
验证码 换一张
取 消