我有這樣的對象數組。他們有重複屬性contactName
和categoryName
值由幾個屬性組成的對象數組,並帶有下劃線
[
{
categoryId:1
categoryName:"Default"
contactName:"Anonymous"
name:"Mobile"
value:"+4417087654"
},
{
categoryId:1
categoryName:"Default"
contactName:"Anonymous"
name:"Email"
value:"[email protected]"
},
{
categoryId:1
categoryName:"Default"
contactName:"Test"
name:"Email"
value:"[email protected]"
},
{
categoryId:1
categoryName:"Default"
contactName:"Test"
name:"Mobile"
value:"+4417087654"
},
{
categoryId:2
categoryName:"Personal"
contactName:"Anonymous"
name:"Email"
value:"[email protected]"
},
{
categoryId:2
categoryName:"Personal"
contactName:"Anonymous"
name:"Email"
value:"[email protected]"
},
{
categoryId:2
categoryName:"Personal"
contactName:"Test"
name:"Email"
value:"[email protected]"
},
{
categoryId:2
categoryName:"Personal"
contactName:"Test"
name:"Email"
value:"[email protected]"
}
]
我通過性能contactName
的值要他們組和categoryName
這可能是這樣的
[
{
"categoryId": 1,
"categoryName": "Default",
entity: [
{
"contactName": "Anonymous",
"addresses": [
{
"name": "Mobile",
"value": "+4417087654"
},
{
"name": "Email",
"value": "[email protected]"
},
{
"name": "Email",
"value": "[email protected]"
}
]
},
{
"contactName": "Test",
"addresses": [
{
"name": "Mobile",
"value": "+4417087654"
},
{
"name": "Email",
"value": "[email protected]"
},
{
"name": "Email",
"value": "[email protected]"
}
]
}]
},
{
"categoryId": 2,
"categoryName": "Personal",
entity: [
{
"contactName": "Anonymous",
"addresses": [
{
"name": "Mobile",
"value": "+4417087654"
},
{
"name": "Email",
"value": "[email protected]"
},
{
"name": "Email",
"value": "[email protected]"
}
]
},
{
"contactName": "Test",
"addresses": [
{
"name": "Mobile",
"value": "+4417087654"
},
{
"name": "Email",
"value": "[email protected]"
},
{
"name": "Email",
"value": "[email protected]"
}
]
}]
}
]
最終輸出應該怎麼樣子的呢? – gurvinder372