gpt4 book ai didi

jquery - 为什么 parseJSON 返回 null

转载 作者:行者123 更新时间:2023-12-03 22:29:22 27 4
gpt4 key购买 nike

我有以下 jQuery/JS 代码

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$.getJSON("http://example/topics", {}, function(data){
console.log( data ); // display the JSON *data* in the web console
console.log( $.parseJSON(data) );
});
</script>

console.log(data) 在 firebug 控制台(firefox 插件)中显示 JSON 数据,但 console.log( $.parseJSON(data) ) 显示 <强>空。

可能的原因是什么。

我需要将 JSON 字符串转换为数组。

最佳答案

我认为是因为 $.getJSON已经解析了数据。 data 是 Javascript 对象。

The success callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and parsed using the $.parseJSON() method.

当然,如果您向我们展示输出,我们可以说更多,但通常,$.getJSON 已经解析了响应。

P.S.:我希望您在实际代码中使用正确的 URL。

关于jquery - 为什么 parseJSON 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6465468/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com