var jsonstring='[{"OrderId" : "or0000000012","CustomerName" : "张雪飞","Phone" : "15823232323","Address" : "东大街 3-659","ClothesMsg" : "","SubmitTime" : "2012/5/17 7:07:02","Status" : "1"},
{"OrderId" : "or0000000011","CustomerName" : "小米","Phone" : "13812345678","Address" : "西大街6-5-6","ClothesMsg" : "","SubmitTime" : "2012/5/17 6:50:39","Status" : "1"}]'
result=$.parseJSON(jsonstring);
$.each(result, function (i, n) {
alert(n.CustomerName);
});
弹出的是undefined的,不知道什么原因,试了了很多方式?之前这样写是没问题的
var jsonstring='[{"OrderId" : "or0000000012","CustomerName" : "张雪飞","Phone" : "15823232323","Address" : "东大街 3-659","ClothesMsg" : "","SubmitTime" : "2012/5/17 7:07:02","Status" : "1"},{"OrderId" : "or0000000011","CustomerName" : "小米","Phone" : "13812345678","Address" : "西大街6-5-6","ClothesMsg" : "","SubmitTime" : "2012/5/17 6:50:39","Status" : "1"}]'; $.each(eval("("+jsonstring+")"), function (i, n) { alert(n.CustomerName); });
注意我给你标红的那几个地方
其实result是我使用了$.parseJson(data)后的数据,后面才$.each(result,function(i,n){})
@Gabriel Zhang: 引号问题,jsonstring的首未要用单引号
如果是如上所述的话,,那应该是你拼错了函数,检查一下parseJSON是否都写成了parseJson
是我这里写错了,程序里面是没错的
我重新试了下,又可以了,估计是我传到前台的json格式是掉了单引号的,谢谢哈