Javascript JSON 在 IE7 中未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2521827/
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
JSON undefined in IE7
提问by Joel
I am using the following line of JQuery code:
我正在使用以下 JQuery 代码行:
$.get('/ajax/buy', {'categoryname':chosenSelected}, function(data) {
data = JSON.parse(data);
...
However, when running it on IE7 I get this error message: JSON undefined:.
但是,在 IE7 上运行它时,我收到此错误消息:JSON undefined:.
How can I use the parser with compatibility to IE7 (and all major browsers)?
如何使用与 IE7(和所有主要浏览器)兼容的解析器?
回答by Darin Dimitrov
You don't need to parse JSON manually. You could use the getJSONfunction:
您不需要手动解析 JSON。您可以使用getJSON函数:
$.getJSON('/ajax/buy', { 'categoryname' : chosenSelected }, function(data) {
// data will be already a parsed JSON object
});
The parsemethod you are trying to call is available in the json2library.
parse您尝试调用的方法在json2库中可用。
回答by Gerardo Lagger
You need add a JSON parser. The old browsers dont include that.
您需要添加一个 JSON 解析器。旧的浏览器不包括。
1 - Go to repository: https://github.com/douglascrockford/JSON-js/
1 - 转到存储库:https: //github.com/douglascrockford/JSON-js/
2 - Download and include json2.js in your site or app.
2 - 下载 json2.js 并将其包含在您的站点或应用程序中。
That is all.
就这些。

