我使用 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"}');
关于javascript - IE10 无法正确解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21225155/