如何使用$.each()遍历下面Json数据
json={"adserver":"HNAS","adconfig":[{"adid":"1","starttime":"0.00","adtype":"pre-roll...
json={"adserver":"HNAS","adconfig":[{"adid":"1","starttime":"0.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"}
{"adid":"2","starttime":"1.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"}
{"adid":"3","starttime":"2.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"}
]}
少几个逗号 补上
json={"adserver":"HNAS","adconfig":[
{"adid":"1","starttime":"0.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"},
{"adid":"2","starttime":"1.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"},
{"adid":"3","starttime":"2.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"},
]} 展开
{"adid":"2","starttime":"1.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"}
{"adid":"3","starttime":"2.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"}
]}
少几个逗号 补上
json={"adserver":"HNAS","adconfig":[
{"adid":"1","starttime":"0.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"},
{"adid":"2","starttime":"1.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"},
{"adid":"3","starttime":"2.00","adtype":"pre-roll","adurl":" http://","adtrick":"false"},
]} 展开
展开全部
这个格式是不能用$.each()的,因为它不是一个数组,这个json的字符串就是一个json对象,不是数组,你可以先把对象中的属性取出来,再用$.each循环第二个属性:
var adserver = json.adserver;
var adconfig = json.adconfig;
$(adconfig).each(function(){
var temp = $(this);//这里是把数组里的每个对象取出来
alert(temp.adid);
alert(temp.adurl);
});
var adserver = json.adserver;
var adconfig = json.adconfig;
$(adconfig).each(function(){
var temp = $(this);//这里是把数组里的每个对象取出来
alert(temp.adid);
alert(temp.adurl);
});
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询