如何使用$.each()遍历下面Json数据

如何使用$.each()遍历下面Json数据,第1张

这个格式是不能用$each()的,因为它不是一个数组,这个json的字符串就是一个json对象,不是数组,你可以先把对象中的属性取出来,再用$each循环第二个属性:
var adserver = jsonadserver;
var adconfig = jsonadconfig;
$(adconfig)each(function(){
var temp = $(this);//这里是把数组里的每个对象取出来
alert(tempadid);
alert(tempadurl);
});

var a=[{"list":[{"count":0,"createTime":"2008-01-25 00:00:00","createUserDept":"","createUserDeptId":"","createUserId":"","createUserName":"","deleteFlag":"0","introduction":"","month":"","pagerSize":0,"periodicalId":"","periodicalName":"admin","periodicalType":"","publishDate":null,"status":"0","updateUserDept":"","updateUserDeptId":"","updateUserId":"","updateUserName":"","year":""},{"count":0,"createTime":"2008-01-25 00:00:00","createUserDept":"","createUserDeptId":"","createUserId":"","createUserName":"","deleteFlag":"0","introduction":"","month":"","pagerSize":0,"periodicalId":"","periodicalName":"admin","periodicalType":"","publishDate":null,"status":"0","updateUserDept":"","updateUserDeptId":"","updateUserId":"","updateUserName":"","year":""}],"pageString":""}]
var list=a[0]list;
for(i=0;i<listlength;i++){
alert(list[i]count);
alert(list[i]createTime);



}
当数组处理,只是成员为对象

var obj = {};
for(var k in obj) {
    //遍历对象,k即为key,obj[k]为当前k对应的值
    consolelog(obj[k]);
}

var typeArr = new Array();
for(var i = 0;i<infoListlength;i++)
{
    typeArrpush(infoList[i]type)   //获取到type的值
    for(var j = 0;j<infoList[i]typeListlength;j++)
    {
        var info = infoList[i]typeList[j];
        alert(infoID);
        alert(infostartDate);
        alert(infoendDate);
        alert(infoadultNum);
        alert(infochildrenNUm);
    }
}

这样就遍历出了所有的数据了 


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/10549479.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-09
下一篇 2023-05-09

发表评论

登录后才能评论

评论列表(0条)

保存