我有以下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))显示为null.
可能的原因是什么.
我需要将JSON字符串转换为数组.
解决方法
我假设因为
$.getJSON已经解析了数据.数据是Javascript对象.
The
successcallback 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.