<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var json = [{
"id": 7,
"parentId": null,
"name": "服装",
"goodsType": null,
"logo": "1",
"recommend": true,
"hotSelling": true,
"sortNum": 1,
"updateOn": null
}, {
"id": 9,
"parentId": 7,
"name": "大衣",
"goodsType": "衣服",
"logo": "1",
"recommend": true,
"hotSelling": true,
"sortNum": 1,
"updateOn": "2170d40e37a447ac8a7f1ae12a6752c1"
}, {
"id": 13,
"parentId": 7,
"name": "棉衣",
"goodsType": "衣服",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": false,
"hotSelling": false,
"sortNum": 1,
"updateOn": null
}, {
"id": 46,
"parentId": 14,
"name": "卡西龙",
"goodsType": "儿童服装",
"logo": "http://bizain01.oss-cn-shenzhen.aliyuncs.com/images/3989002422360997923/42300614d5fc4c5a9c5130329aa5df89",
"recommend": true,
"hotSelling": true,
"sortNum": 1,
"updateOn": null
}, {
"id": 8,
"parentId": null,
"name": "家具",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 2,
"updateOn": "1"
}, {
"id": 14,
"parentId": 7,
"name": "棉衣",
"goodsType": "家具,儿童服装",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png0",
"recommend": false,
"hotSelling": true,
"sortNum": 2,
"updateOn": "2170d40e37a447ac8a7f1ae12a6752c1"
}, {
"id": 17,
"parentId": 9,
"name": "呢子大衣2",
"goodsType": "儿童服装",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": false,
"hotSelling": true,
"sortNum": 2,
"updateOn": null
}, {
"id": 44,
"parentId": 13,
"name": "小服装",
"goodsType": "儿童服装",
"logo": "",
"recommend": true,
"hotSelling": true,
"sortNum": 2,
"updateOn": null
}, {
"id": 11,
"parentId": null,
"name": "超市",
"goodsType": null,
"logo": "",
"recommend": false,
"hotSelling": false,
"sortNum": 3,
"updateOn": null
}, {
"id": 15,
"parentId": 7,
"name": "测试棉衣",
"goodsType": "衣服衣服衣服衣服衣",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": false,
"hotSelling": true,
"sortNum": 3,
"updateOn": null
}, {
"id": 16,
"parentId": 7,
"name": "儿童服装",
"goodsType": "儿童服装",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 3,
"updateOn": "ec0455cbf07b4244a4ae791c1c96e3a1"
}, {
"id": 20,
"parentId": 18,
"name": "桌子2",
"goodsType": "家具",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 3,
"updateOn": null
}, {
"id": 12,
"parentId": null,
"name": "海淘购",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": false,
"hotSelling": false,
"sortNum": 4,
"updateOn": "1"
}, {
"id": 18,
"parentId": 8,
"name": "桌子",
"goodsType": "家具",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 4,
"updateOn": null
}, {
"id": 51,
"parentId": 13,
"name": "大服装",
"goodsType": "成人服装",
"logo": "http://bizain01.oss-cn-shenzhen.aliyuncs.com/images/3989002422360997924/328bbecf5571482a885c7d329958d89f",
"recommend": true,
"hotSelling": true,
"sortNum": 5,
"updateOn": null
}, {
"id": 52,
"parentId": 8,
"name": "具",
"goodsType": "儿童服装",
"logo": "https://bizain.net/wxapp/image/BWT.png",
"recommend": true,
"hotSelling": true,
"sortNum": 6,
"updateOn": null
}, {
"id": 23,
"parentId": 7,
"name": "服装1",
"goodsType": "儿童服装",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 7,
"updateOn": null
}, {
"id": 29,
"parentId": null,
"name": "test1",
"goodsType": null,
"logo": "",
"recommend": true,
"hotSelling": true,
"sortNum": 7,
"updateOn": null
}, {
"id": 53,
"parentId": 8,
"name": "测试家具",
"goodsType": null,
"logo": "https://bizain.net/wxapp/image/BWT.png",
"recommend": true,
"hotSelling": true,
"sortNum": 7,
"updateOn": null
}, {
"id": 24,
"parentId": 7,
"name": "服装2",
"goodsType": "儿童服装",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 8,
"updateOn": null
}, {
"id": 30,
"parentId": null,
"name": "test2",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/manager/api/file/download/85279b8dda534cd1ab821ac908c1e2d6.jpg",
"recommend": true,
"hotSelling": true,
"sortNum": 8,
"updateOn": null
}, {
"id": 54,
"parentId": 8,
"name": "小家具",
"goodsType": "儿童服装,成人服装,测试类型",
"logo": "https://bizain.net/wxapp/image/BWT.png",
"recommend": true,
"hotSelling": true,
"sortNum": 8,
"updateOn": null
}, {
"id": 25,
"parentId": 7,
"name": "服装3",
"goodsType": "儿童服装",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 9,
"updateOn": null
}, {
"id": 31,
"parentId": null,
"name": "test3",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/manager/api/file/download/0bbc518300b745e6ad0a38ab57f4749b.jpg",
"recommend": true,
"hotSelling": true,
"sortNum": 9,
"updateOn": null
}, {
"id": 43,
"parentId": 9,
"name": "呢子大衣6",
"goodsType": "儿童服装",
"logo": "",
"recommend": true,
"hotSelling": true,
"sortNum": 9,
"updateOn": null
}, {
"id": 26,
"parentId": 7,
"name": "服装4",
"goodsType": "儿童服装",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 10,
"updateOn": null
}, {
"id": 32,
"parentId": null,
"name": "test5",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/manager/api/file/download/bbcc0d42984344558861c2ccbf3e7416.jpg",
"recommend": true,
"hotSelling": true,
"sortNum": 10,
"updateOn": null
}, {
"id": 42,
"parentId": 9,
"name": "呢子大衣5",
"goodsType": "儿童服装",
"logo": "",
"recommend": true,
"hotSelling": true,
"sortNum": 10,
"updateOn": null
}, {
"id": 27,
"parentId": 7,
"name": "服装5",
"goodsType": "儿童服装",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 11,
"updateOn": null
}, {
"id": 33,
"parentId": null,
"name": "test6",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/manager/api/file/download/4b782b55bfc14418a8f2173d23b304c5.jpg",
"recommend": true,
"hotSelling": true,
"sortNum": 11,
"updateOn": null
}, {
"id": 41,
"parentId": 9,
"name": "呢子大衣4",
"goodsType": "儿童服装",
"logo": "",
"recommend": true,
"hotSelling": true,
"sortNum": 11,
"updateOn": null
}, {
"id": 28,
"parentId": 7,
"name": "服装6",
"goodsType": "儿童服装",
"logo": "https://bizain.net/test/api/platform/business/api/file/download/abyo.png",
"recommend": true,
"hotSelling": true,
"sortNum": 12,
"updateOn": null
}, {
"id": 34,
"parentId": null,
"name": "test7",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/manager/api/file/download/5ed6f6922a0640179e948aac1ae3aa04.jpg",
"recommend": true,
"hotSelling": true,
"sortNum": 12,
"updateOn": null
}, {
"id": 40,
"parentId": 9,
"name": "呢子大衣3",
"goodsType": "儿童服装",
"logo": "",
"recommend": true,
"hotSelling": true,
"sortNum": 12,
"updateOn": null
}, {
"id": 35,
"parentId": null,
"name": "test8",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/manager/api/file/download/3c7f3b035f7944a59e1aa6849cf20699.png",
"recommend": true,
"hotSelling": true,
"sortNum": 13,
"updateOn": null
}, {
"id": 38,
"parentId": 7,
"name": "服装7",
"goodsType": "儿童服装",
"logo": "",
"recommend": true,
"hotSelling": true,
"sortNum": 13,
"updateOn": null
}, {
"id": 39,
"parentId": 9,
"name": "呢子大衣1",
"goodsType": "儿童服装",
"logo": "",
"recommend": true,
"hotSelling": true,
"sortNum": 13,
"updateOn": null
}, {
"id": 36,
"parentId": null,
"name": "test9",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/manager/api/file/download/42a982e885ac4d158cb2ced9dbb39669.png",
"recommend": true,
"hotSelling": true,
"sortNum": 14,
"updateOn": null
}, {
"id": 37,
"parentId": null,
"name": "test10",
"goodsType": null,
"logo": "https://bizain.net/test/api/platform/manager/api/file/download/a5cc07c9cbce49af8dd02ef79b1af266.png",
"recommend": true,
"hotSelling": true,
"sortNum": 18,
"updateOn": null
}, {
"id": 48,
"parentId": 21,
"name": "三鹿",
"goodsType": null,
"logo": "http://bizain01.oss-cn-shenzhen.aliyuncs.com/images/3989002422360997923/3b0f9e80bbc440bc976f8aa019e5537a",
"recommend": true,
"hotSelling": true,
"sortNum": 66,
"updateOn": null
}, {
"id": 50,
"parentId": 22,
"name": "小白龙",
"goodsType": null,
"logo": "http://bizain01.oss-cn-shenzhen.aliyuncs.com/images/3989002422360997923/78a4e946f593477ca897e2d2a7ed96df",
"recommend": false,
"hotSelling": true,
"sortNum": 80,
"updateOn": null
}, {
"id": 49,
"parentId": 15,
"name": "阿玛尼",
"goodsType": "儿童服装",
"logo": "http://bizain01.oss-cn-shenzhen.aliyuncs.com/images/3989002422360997923/cbfa8e4e4b8b4cc4b99cea9280e10acf",
"recommend": true,
"hotSelling": true,
"sortNum": 99,
"updateOn": null
}]
var newjson = [];
for(var i = 0; i < json.length; i++) {
if(!json[i].parentId) newjson.push(json[i]);
for(var j = i + 1; j < json.length; j++) {
if(json[i].id == json[j].parentId) {
json[i].children = json[i].children || [];
json[i].children.push(json[j]);
} else if(json[j].id == json[i].parentId) {
json[j].children = json[j].children || [];
json[j].children.push(json[i]);
}
}
}
console.log(newjson)
</script>
</body>
</html>
json转treeJson
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1、JSONString转换为字典 2、字典转换为JSONString
- 首先给大家带来网上常见的Json字符串转字典,字典转Json字符串代码 Json字符串转字典 字典转Json字符串...
- json格式字符串转字典不能直接转化需要先转换成Data,在转化成字,同样字典也不能直接转换成json格式字符串。...