我有一系列物品。所有项目都包含start_date。
根据开始日期,我想创建一个新数组,从start_date作为键开始,然后是当天内的每个条目。
因此:
(json中的示例,原始数组更长,每天有多个条目)
[
{
"Booking_id": "135474",
"Start_date": "2017-08-11 09:10:00",
"End_date": "2017-08-11 09:59:00",
"Max_participants": null,
"Description": "Schedule Sports Hall 3",
"Trainer": "1053",
"Memo": null,
"Cms_id": null,
"Product_id": "85",
"First_name": "Teri",
"Middle_name": null,
"Last_name": "Hatcher"
},
{
"Booking_id": "133718",
"Start_date": "2017-08-11 10:00:00",
"End_date": "2017-08-11 10:59:00",
"Max_participants": null,
"Description": "Schedule Sports Hall 3",
"Trainer": "1053",
"Memo": null,
"Cms_id": null,
"Product_id": "85",
"First_name": "Teri",
"Middle_name": null,
"Last_name": "Hatcher"
},
{
"Booking_id": "135514",
"Start_date": "2017-08-12 11:00:00",
"End_date": "2017-08-12 11:59:00",
"Max_participants": null,
"Description": "Schedule Sports Hall 3",
"Trainer": "1053",
"Memo": null,
"Cms_id": null,
"Product_id": "85",
"First_name": "Teri",
"Middle_name": null,
"Last_name": "Hatcher"
}
]
我想这样做:
{
"2017-08-11" : [ {
"Booking_id": "135474",
"Start_date": "2017-08-11 09:10:00",
"End_date": "2017-08-11 09:59:00",
"Max_participants": null,
"Description": "Schedule Sports Hall 3",
"Trainer": "1053",
"Memo": null,
"Cms_id": null,
"Product_id": "85",
"First_name": "Teri",
"Middle_name": null,
"Last_name": "Hatcher"
},
{
"Booking_id": "133718",
"Start_date": "2017-08-11 10:00:00",
"End_date": "2017-08-11 10:59:00",
"Max_participants": null,
"Description": "Schedule Sports Hall 3",
"Trainer": "1053",
"Memo": null,
"Cms_id": null,
"Product_id": "85",
"First_name": "Teri",
"Middle_name": null,
"Last_name": "Hatcher"
}
],
"2017-08-12" => ,
[{
"Booking_id": "135514",
"Start_date": "2017-08-12 11:00:00",
"End_date": "2017-08-12 11:59:00",
"Max_participants": null,
"Description": "Schedule Sports Hall 3",
"Trainer": "1053",
"Memo": null,
"Cms_id": null,
"Product_id": "85",
"First_name": "Teri",
"Middle_name": null,
"Last_name": "Hatcher"
}]
}
我不确定json是否准确,但我认为你明白了。我自己尝试了这个,但发现了一些性能问题,导致一切都耗时太长。