IE6 (IE7) 上的 JSON

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2503175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 17:26:21  来源:igfitidea点击:

JSON on IE6 (IE7)

jsoninternet-explorerinternet-explorer-7internet-explorer-6

提问by David Thorisson

Sorry for my inpatience but after weeks staying up late and just having put my web online, I just don't have any left energy to debug... I just can't Google how to implement JSON on IE6 & IE7... I'm using

很抱歉我的不耐烦,但经过几个星期的熬夜,只是把我的网络放在网上,我只是没有任何剩余的精力来调试......我只是无法谷歌如何在 IE6 和 IE7 上实现 JSON......我正在使用

JSON.stringify(...)

From what I understand JSON is not built in on IE6-7 and has to be dynamically added in in-line code... how do you do that?

据我了解,JSON 不是内置于 IE6-7 中的,必须在内嵌代码中动态添加......你是怎么做到的?

I already have jQuery - is it my correct understanding that their JSON engine relies on the browser native one?

我已经有了 jQuery - 我是否正确理解他们的 JSON 引擎依赖于浏览器原生引擎?

Then some comment on invalid JSON code that makes IE6-7 fail, but I thought it wasn't native in IE6-7?

然后对使 IE6-7 失败的无效 JSON 代码进行了一些评论,但我认为它不是 IE6-7 中的原生代码?

Anyone?

任何人?

回答by CMS

Since you want to use the JSON.stringifymethod, you will need to include the JSON3 parserin order to support it on IE < 8.

由于您想使用该JSON.stringify方法,您将需要包含JSON3 解析器,以便在 IE < 8 上支持它。

This library complies with the standard methods of the ECMAScript 5th Edition specification and it checks if there is a native implementation available, so on modern browser this native implementation will be used.

该库符合 ECMAScript 第 5 版规范的标准方法,并检查是否有可用的本机实现,因此在现代浏览器上将使用此本机实现。

回答by Padhu

Just include json2.jsin your file to play around with JSON. It'll also work in IE 9 .

只需在您的文件中包含json2.js即可使用 JSON。它也适用于 IE 9 。

回答by naivists

There must be something misunderstood. The object notation has been in JavaScript for a while now (as far as I understand, it's a core concept of JavaScript). I mean, the ability to write code like var o= {a:"b"};
So, if you can do this, you can also call eval('var o= {a:"b"};')and that's the way you "implement JSON" in any browser.

一定是有什么误解。对象表示法在 JavaScript 中已经有一段时间了(据我所知,它是 JavaScript 的核心概念)。我的意思是,像var o= {a:"b"};
这样编写代码的能力,如果你能做到这一点,你也可以调用eval('var o= {a:"b"};'),这就是你在任何浏览器中“实现 JSON”的方式。

UPDATE: Re-read your post and finally got the point that the problem is serializing objects, not deserializing them. Then you can use the JavaScript library for that: https://github.com/douglascrockford/JSON-js/blob/master/json2.js

更新:重新阅读你的帖子,终于明白问题是序列化对象,而不是反序列化它们。然后你可以使用 JavaScript 库:https: //github.com/douglascrockford/JSON-js/blob/master/json2.js

回答by Matt

"dynamically added in-line code" is using the functionality provided by Douglas Crockfords json2 library, or jQuery's own implementation if the browser version doesn't support it natively.

“动态添加的内嵌代码”是使用 Douglas Crockfords json2 库提供的功能,如果浏览器版本本身不支持它,则使用 jQuery 自己的实现。

jQuery does not rely on any JSON decoding functionality provided by the browser. If the browser does support JSON decoding, then jQuery will use it.

jQuery 不依赖浏览器提供的任何 JSON 解码功能。如果浏览器确实支持 JSON 解码,那么 jQuery 将使用它。