我有一个这样的数组: -
[
{"brand":"cadbury","category":"silk"},
{"brand":"biba","category":"tops"},
{"brand":"cadbury","category":"fruitnut"}
]
我希望将其转换为以下格式,尝试了许多方法,但没有成功: -
[
{"brand":"cadbury","category":[{"name":"silk"},{"name":"fruitnut"}]},
{"brand":"biba","category": [{"name":"tops"}] }
]
基本上在循环之后,我想将所有品牌组合在一起。