javascript - IE10 无法正确解析 JSON

标签 javascript json internet-explorer

我使用 JSFiddle 将问题简化为简单的问题:http://fiddle.jshell.net/ZuV7J/

这可以在 Firefox 和 Chrome 中正确解析简单的 JSON 字符串,但在 IE8、IE9 和 IE10 中返回一个空对象(无论使用什么 JSON 字符串)。我还没有尝试过 IE11。

无论我是否加载 Crockford 的 JSON2.js 库,都会发生这种情况。

最佳答案

在 Internet Explorer window.event

Represents the state of an event, such as the element in which the event occurred, the state of the keyboard keys, the location of the mouse, and the state of the mouse buttons.

无法分配给它。

如果没有 var,您的代码 event = JSON.parse('{"var":"value"}'); 会尝试分配给 window。不允许的事件

更改为在 var 中使用不同的变量名称或前缀事件,以便您的代码显示为:var event=JSON.parse('{"var":"value"}');

http://fiddle.jshell.net/ZuV7J/1/

关于javascript - IE10 无法正确解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21225155/

相关文章:

javascript - Django 模板中的嵌入数据太大/未显示?

jquery - javascript json ajax数据解析

linux - http 站点不会在 IE 上转发到 https

internet-explorer - 使用 Powershell 终止所有运行时间超过 5 分钟的 Internet Explorer 进程

javascript - 由于 AngularJS 的 IE 缓存,我必须单击两次才能添加/删除项目

javascript - hide() 和 on() 在 Internet Explorer (IE) 上不起作用

javascript - 为什么我的 JavaScript 函数在我的 jQuery load() 调用完成加载之前运行?

java - Android 应用程序在解析 JSON 时不断失败

java - 从 JAVA 内部 JSON 对象读取

javascript - Ajax - 显示2个不同的json数据