首页 新闻 搜索 专区 学院

帮忙使用JQUERY解析下JSON

0
悬赏园豆:5 [已解决问题] 解决于 2017-04-30 17:14

JSON:

复制代码

[{
"Id": 15,
"SiteId": 6,
"CategoryId": 25,
"AttrName": "颜色",
"Sort": 0,
"Status": 1,
"IsRequired": true,
"AddDate": "/Date(1493537367920)/",
"List": [{
"Id": 14,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 15,
"AttrValue": "#F6358A",
"DisplayValue": "红色",
"Sort": 1,
"Status": 1,
"AddDate": "/Date(1493479729483)/"
},
{
"Id": 15,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 15,
"AttrValue": "#3BB9FF",
"DisplayValue": "蓝色",
"Sort": 2,
"Status": 1,
"AddDate": "/Date(1493479729487)/"
},
{
"Id": 16,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 15,
"AttrValue": "#000000",
"DisplayValue": "黑色",
"Sort": 3,
"Status": 1,
"AddDate": "/Date(1493479729487)/"
},
{
"Id": 17,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 15,
"AttrValue": "#FFFFFF",
"DisplayValue": "白色",
"Sort": 4,
"Status": 1,
"AddDate": "/Date(1493479729487)/"
}]
},
{
"Id": 16,
"SiteId": 6,
"CategoryId": 25,
"AttrName": "规格",
"Sort": 2,
"Status": 1,
"IsRequired": true,
"AddDate": "/Date(1493537843597)/",
"List": [{
"Id": 18,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 16,
"AttrValue": "8G",
"DisplayValue": "8G",
"Sort": 1,
"Status": 1,
"AddDate": "/Date(1493537843607)/"
},
{
"Id": 19,
"SiteId": 6,
"CategoryId": 25,
"GoodAttrId": 16,
"AttrValue": "16G",
"DisplayValue": "16G",
"Sort": 2,
"Status": 1,
"AddDate": "/Date(1493537843607)/"
}]
}]

复制代码

我使用

$.each(data, function (k, p) {
var str="<div class=\"form-group\">";
str+="<label class=\"control-label col-md-2\">"+p.AttrName+"</label>";
str+="<div class=\"col-md-8\">";
$.each(data.List,function(k1,p1){

});
str+="</div></div>";
$("#GoodAttrs").append(str);
});

只能解析出第一层,第二层死活解析不出来。

要求格式:

颜色

  红色   蓝 色   黑色

规格

  8G  16G   32G

DZCMS的主页 DZCMS | 初学一级 | 园豆:5
提问于:2017-04-30 17:06
< >
分享
最佳答案
0

把问题发出来,自己就找到问题了。。。。也是醉了。

第二层应该是p.List

DZCMS | 初学一级 |园豆:5 | 2017-04-30 17:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册