jquery遍历不了json数组呢

2017-08-26 09:00 出处:360java.com 作者:360java  阅读()
var jsonstring=#39;[{quot;OrderIdquot; : quot;or0000000012quot;,quot;CustomerNamequot; : quot;张雪飞quot;,quot;Phonequot; : quot;15823232323quot;,quot;Address

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的首未要用单引号

分享到:
本文标签: jQuery, Web前端

相关文章

发表评论(共条评论)愿您的每句评论,都能给大家的生活添色彩,带来共鸣,带来思索,带来快乐。

Copyright (C) java学习 360java 360java.com, All Rights Reserved.

苏ICP备16022210号