----------这是testA.php -------------------------
[{"msgCD":"OK","msgSTR":"Hi"}]
----------这是testB.html -------------------------
$(document).ready(function(){ $('.submit').click(function(){
$.getJSON('testA.php',function(data){
$.each(data,function(i,n){
$('#message').append(n['msgCD']+'</br>');
});
});
return false;});});
使用Chrome和Firefox,JSON输出“HI”但IE,它根本不起作用!天啊:(
答案 0 :(得分:0)
您有一个对象包装在一个数组中,因此您无法直接访问该对象:
var foo = [{"msgCD":"OK","msgSTR":"Hi"}]
foo.msgCD // undefined
foo[0].msgCD // "OK"
编辑: 我还建议你使用chrome控制台,只需创建一个console.log(n),你就可以浏览你的对象了。