Javascript SCRIPT5009:“JSON”未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8332362/
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
SCRIPT5009: 'JSON' is undefined
提问by Tim Joyce
I get the following error in IE 9 SCRIPT5009: 'JSON' is undefined
only when in compatability mode. the line causing this error is
SCRIPT5009: 'JSON' is undefined
只有在兼容模式下,我才会在 IE 9 中收到以下错误。导致此错误的行是
JSON.stringify(togObj.Answers)
The error does not occur in ie (non-compatability mode), Chrome or Firefox. Any idea what's going on here?
该错误不会在 ie(非兼容模式)、Chrome 或 Firefox 中发生。知道这里发生了什么吗?
回答by NakedBrunch
See here for a blog post explaining the situation: Resolve JSON is Undefined Error in Internet Explorer
请参阅此处查看解释该情况的博客文章:解决 JSON 是 Internet Explorer 中的未定义错误
Include the JSON libraryin your page and you should be good to go.
在您的页面中包含JSON 库,您应该很高兴。
回答by phihag
JSON is not available in compatibility mode IE:
JSON在兼容模式 IE 下不可用:
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards.
以下文档模式不支持:Quirks、Internet Explorer 6 标准、Internet Explorer 7 标准。
Since you shouldn't be using (or worse, reyling on ) compatibility modes in the first place, you should switch IE to standards-mode by adding a valid doctype.
由于您首先不应该使用(或更糟的是,依赖于)兼容性模式,因此您应该通过添加有效的文档类型将 IE 切换到标准模式。
回答by Joe
Yes, JSON is defined natively in modern browsers, but not in IE. You need to import a library. For example, http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js
是的,JSON 是在现代浏览器中本地定义的,但不是在 IE 中定义的。您需要导入一个库。例如http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js
回答by rajar
I have done LOCAL Jquery added .NEt 2.0 code testing, it works fine without any problem. But after migrate the code to IIS v6 server then access from same IE browser, then problem appear "JSON" undefined. After read this recommendation, downlode the file json2.js and add below into source code.
我已经完成了 LOCAL Jquery 添加的 .NET 2.0 代码测试,它运行良好,没有任何问题。但是在将代码迁移到 IIS v6 服务器然后从同一个 IE 浏览器访问后,问题出现“JSON”未定义。阅读此建议后,下载文件 json2.js 并将以下内容添加到源代码中。
<script type="text/javascript" src="json2.js"></script>
EVERYTHING WORKING Fine.
一切正常。
Good Thank you.
好的谢谢你。
回答by Huy
Just an update (2013!) to the links provided above-
只是对上面提供的链接的更新(2013!)-
Per http://www.json.org/js.html, a link at the bottom of the page will refer you to the latest implementation:
根据http://www.json.org/js.html,页面底部的链接将向您介绍最新的实现:
回答by Mohammed Rafeeq
You need to include json2.js
你需要包含 json2.js
see json2 inclusion
for more details. There are cases where we have to deal with cases where clients use IE7 standards. So our code had to cater to such cases too. Ours being a retail website is accessed by hundreds of clients who use IE7 standards. Including json2 solves this issue
更多细节。在某些情况下,我们必须处理客户端使用 IE7 标准的情况。所以我们的代码也必须迎合这种情况。我们的零售网站被数百名使用 IE7 标准的客户访问。包括 json2 解决了这个问题
回答by iMatoria
If you are using jQuery library at your page, than you could use $.parseJSON
.
如果您在页面上使用 jQuery 库,则可以使用$.parseJSON
.