对不起,如果这个问题之前被问过,请原谅我,但是我找不到一个好的例子来完成我想要做的事情。也许我只是没有寻找正确的东西。如果有关于此的解释,请纠正我。无论如何...
我有这样结构的JSON数据...
{"Result":[
{"Level":"ML","TeamName":"Team 1","League":"League 1"},
{"Level":"ML","TeamName":"Team 2","League":"League 2"},
{"Level":"ML","TeamName":"Team 3","League":"League 3"},
{"Level":"3A","TeamName":"Team 4","League":"League 1"},
{"Level":"3A","TeamName":"Team 5","League":"League 2"},
{"Level":"3A","TeamName":"Team 6","League":"League 3"},
{"Level":"2A","TeamName":"Team 7","League":"League 1"},
{"Level":"2A","TeamName":"Team 8","League":"League 2"},
{"Level":"2A","TeamName":"Team 9","League":"League 3"},
]}
我想要将它分组或重构为以下方式...
{"Result":[
{"ML":[
{"TeamName":"Team 1","League":"League 1"},
{"TeamName":"Team 2","League":"League 2"},
{"TeamName":"Team 3","League":"League 3"}
]},
{"3A":[
{"TeamName":"Team 4","League":"League 1"},
{"TeamName":"Team 5","League":"League 2"},
{"TeamName":"Team 6","League":"League 3"}
]},
{"2A":[
{"TeamName":"Team 7","League":"League 1"},
{"TeamName":"Team 8","League":"League 2"},
{"TeamName":"Team 9","League":"League 3"}
]}
]}
我该如何使用JavaScript/jQuery来实现这一点?不幸的是,我无法编辑服务器发送给我的内容。