js怎么遍历json数组对象, 如何遍历出content里面的数值,格式如下
js怎么遍历json数组对象,如何遍历出content里面的数值,格式如下varcontent=infoList:[{type:1,typeList:[{ID:101,s...
js怎么遍历json数组对象, 如何遍历出content里面的数值,格式如下var content= infoList: [
{ type: 1, typeList: [{ ID: 101, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] },
{ type: 2, typeList: [{ ID: 102, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 15, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 18, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] },
{ type: 3, typeList: [{ ID: 11, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 13, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] },
{ type: 4, typeList: [{ ID: 10, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 9, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] },
{ type: 5, typeList: [{ ID: 16, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 23, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] }]
} 展开
{ type: 1, typeList: [{ ID: 101, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] },
{ type: 2, typeList: [{ ID: 102, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 15, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 18, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] },
{ type: 3, typeList: [{ ID: 11, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 13, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] },
{ type: 4, typeList: [{ ID: 10, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 9, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] },
{ type: 5, typeList: [{ ID: 16, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 },
{ ID: 23, startDate: '2016-09-08', endDate: '2016-09-08', adultNum: 0, childrenNum: 0 }] }]
} 展开
1个回答
展开全部
var typeArr = new Array();
for(var i = 0;i<infoList.length;i++)
{
typeArr.push(infoList[i].type) //获取到type的值
for(var j = 0;j<infoList[i].typeList.length;j++)
{
var info = infoList[i].typeList[j];
alert(info.ID);
alert(info.startDate);
alert(info.endDate);
alert(info.adultNum);
alert(info.childrenNUm);
}
}
这样就遍历出了所有的数据了
追问
感谢,完全是我想要的结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询