我试图在json中forEach值,并通过使用内部的map函数将所需的值推送到数组中。
[
{
"detail": {
"id": 89,
"content": "123",
"type": "one",
"company": "minsu",
"certificationNum": "minsu"
},
"ingredientList": [
{
"id": 161,
"content": "32523523",
"functionalList": [
{
"id": 129,
"valueUnit": "mg"
}
]
},
{
"id": 162,
"content": "162",
"functionalList": [
{
"id": 130,
"valueUnit": "cm"
}
]
}
]
},
{
"detail": {
"id": 91,
"content": "332",
"type": "two",
"company": "sss",
"certificationNum": "1123-522"
},
"ingredientList": [
{
"id": 164,
"content": "hi",
"functionalList": [
{
"id": 132,
"valueUnit": "kg"
},
{
"id": 133,
"valueUnit": "g"
}
]
},
{
"id": 165,
"content": "succes",
"functionalList": [
{
"id": 134,
"valueUnit": "fie"
},
{
"id": 135,
"valueUnit": "fy"
}
]
}
]
}
]
这是一个简单的json,
我想将json数据值推送到一个数组中,并将它们作为这些值。
[
{
"content": "123",
"type": "one",
"certificationNum": "minsu",
"functionalList": {
{
"id": 129,
"valueUnit": "mg"
},
{
"id": 130,
"valueUnit": "cm"
}
}
},
{
"content": "332",
"type": "two",
"certificationNum": "1123-522",
"functionalList": {
{
"id": 132,
"valueUnit": "kg"
},
{
"id": 133,
"valueUnit": "g"
},
{
"id": 134,
"valueUnit": "fie"
},
{
"id": 135,
"valueUnit": "fy"
}
}
}
]
let SeedDetailArray = new Array();
SeedValue.forEach(function(id: any) {
Object.keys(id).forEach(function(props) {
SeedDetailArray.push({
content: id[props]["content"],
type: id[props]["type"],
certificationNum: id[props]["certificationNum"],
functionalList: id[props]["functionalList"],
});
});
})
安慰log(种子值);
[
{
"content": "123",
"type": "one",
"certificationNum": "minsu",
},
{
"content": "332",
"type": "two",
"certificationNum": "1123-522",
}
]
我把
Seed Value json
在里面
Seed Detail Array
具有
detail
forEach语句,但我不知道如何将值放入
functionList
.
如何创建这样的json?
[
{
"content": "123",
"type": "one",
"certificationNum": "minsu",
"functionalList": {
{
"id": 129,
"valueUnit": "mg"
},
{
"id": 130,
"valueUnit": "cm"
}
}
},
{
"content": "332",
"type": "two",
"certificationNum": "1123-522",
"functionalList": {
{
"id": 132,
"valueUnit": "kg"
},
{
"id": 133,
"valueUnit": "g"
},
{
"id": 134,
"valueUnit": "fie"
},
{
"id": 135,
"valueUnit": "fy"
}
}
}
]