javascript evalJSON 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5618855/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:47:48  来源:igfitidea点击:

evalJSON is not a function

javascriptjquery

提问by Manu

following is my code.

以下是我的代码。

$("document").ready(function () {
    var dataName = new Array();
    $.get('<%=request.getContextPath()%>/empBox/ajaxToGetCodes.do', function (responseText) {
        var JSONcustomers = $.evalJSON(responseText);
        var total = JSONcustomers["arrayObj1"].length;
        var index = 0;
    });

Although i'm getting the response text. But its not able to convert it to json. Giving the following error.

虽然我收到了回复文本。但它无法将其转换为 json。给出以下错误。

$.evalJSON is not a function.

$.evalJSON is not a function.

Am adding all the necessary library to it. jquery-json.js and jquery.js

我正在向其中添加所有必要的库。jquery-json.js 和 jquery.js

Any idea, what may be the problem??

任何想法,可能是什么问题?

采纳答案by Manu

Thanks all!!

谢谢大家!!

Actually due to some other internal script problem, the jquery-json plugin file although showing loaded in the DOM but was not recognizable by the calling method.

实际上由于其他一些内部脚本问题,jquery-json 插件文件虽然显示已加载到 DOM 中,但无法被调用方法识别。

So i used $.getScript, now my code looks like the following

所以我使用了 $.getScript,现在我的代码如下所示

$.get('<%=request.getContextPath()%>/empBox/ajaxToGetCodes.do', function (responseText) {
$.getScript("<%=request.getContextPath()%>/web/include/js/jquery.json-2.2.min.js",
    var JSONcustomers = $.evalJSON(responseText);
    var total = JSONcustomers["arrayObj1"].length;
    var index = 0;
});
});

And, this solved my problem!! :)

而且,这解决了我的问题!!:)

回答by Mark Kahn

It's $.parseJSON

它是 $.parseJSON

...more text to satisify 30 char limit

...更多文字以满足 30 个字符的限制

回答by Peeter

Instead of manually parsing the JSON, why not simply use getJSON that does this for you?

与其手动解析 JSON,为什么不简单地使用为您执行此操作的 getJSON 呢?

Read the documentation at: http://api.jquery.com/jQuery.getJSON/

阅读文档:http: //api.jquery.com/jQuery.getJSON/

回答by Kent

I think it's $.parseJSON

我想这是 $.parseJSON

If you want to use evalJSON, here's the plugin: http://code.google.com/p/jquery-json/

如果你想使用 evalJSON,这里是插件:http: //code.google.com/p/jquery-json/