本文介绍了为什么parseJSON返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下jQuery/JS代码
I have following jQuery/JS code
<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))显示 null .
console.log(data) shows JSON data within firebug console (firefox add-on), but console.log( $.parseJSON(data) ) shows null.
可能是什么原因.
我需要将JSON字符串转换为数组.
I need to convert JSON string into array.
推荐答案
我认为是因为 $.getJSON
已经解析了数据. data
是Javascript对象.
I assume because $.getJSON
already parsed the data. data
is Javascript object.
如果您向我们展示输出,我们当然可以说更多,但是通常$.getJSON
已经解析了响应.
Of course we could say more if you show us the output, but normally, $.getJSON
already parses the response.
P.S .:希望您在真实代码中使用正确的网址.
P.S.: I hope you use a proper URL in your real code.
这篇关于为什么parseJSON返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!