我有一个如下所示的数据集:
{
"Stops": [
{
"Name": "COLUMBIA RD NW + MINTWOOD PL NW",
"Routes": [
"42",
"43",
"H1",
"L2"
]
}
]
}
另一个看起来像这样:
{
"Predictions": [
{
"DirectionText": "North to Mt Pleasant Via Adams Morgan",
"Minutes": 7,
"RouteID": "42"
},
{
"DirectionText": "North to Mt Pleasant Via Adams Morgan",
"Minutes": 25,
"RouteID": "42"
},
{
"DirectionText": "North to Chevy Chase Circle",
"Minutes": 32,
"RouteID": "L2"
},
{
"DirectionText": "North to Mt Pleasant Via Adams Morgan",
"Minutes": 36,
"RouteID": "42"
},
{
"DirectionText": "North to Mt Pleasant Via Adams Morgan",
"Minutes": 58,
"RouteID": "42"
},
{
"DirectionText": "North to Mt Pleasant Via Adams Morgan",
"Minutes": 69,
"RouteID": "42",
}
],
"StopName": "Columbia Rd Nw + Mintwood Pl Nw"
}
我想在第一组中结合 Route ID 上的数据,专门添加要设置的分钟数。所以输出会是这样的:
{
"Stops": [
{
"Name": "COLUMBIA RD NW + MINTWOOD PL NW",
"Routes": [
{
"42": [
{
"Minutes": [7, 25,36,58,69]
}
],
"43": [
{
"Minutes": []
}
],
"H1":[
{
"Minutes": []
}
],
"L2": [
{
"Minutes": [32]
}
]
}
],
"StopID": "1001779"
}
]
}
我不知道如何编写一些 javascript/jquery 来进行这种合并。有任何想法吗?