简体   繁体   English

$ .parseJSON无法在Internet Explorer 10中运行

[英]$.parseJSON not working in Internet Explorer 10

$.parseJSON is working great in Firefox, Chrome, and Safari using the code below. $ .parseJSON使用下面的代码在Firefox,Chrome和Safari中运行良好。 However, in Internet Explorer 10, the script fails to yield a valid object. 但是,在Internet Explorer 10中,脚本无法生成有效对象。

Here's the jsFiddle: http://jsfiddle.net/gahathat/sq6Lb/ 这是jsFiddle: http//jsfiddle.net/gahathat/sq6Lb/

And the js code: 和js代码:

string = '{"result":"success"}';
$('#json_string').text(string);
item = $.parseJSON(string);
$('#json_result').text(item.result);

Is there a workaround for Internet Explorer that would correct this error? 是否有Internet Explorer的解决方法可以纠正此错误?

This should work: 这应该工作:

$(function() {
    var string = '{"result":"success"}';

    $('#json_string').text(string);

    var item = $.parseJSON(string);
    $('#json_result').text(item.result);
});

IE has a global object called 'item' which can't be overwritten. IE有一个名为“item”的全局对象,无法覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM