import json
accept_suggested_timings = """{"2023-11-20 00:00:00":[{"startDateTime":"2023-11-20 14:00:00","endDateTime":"2023-11-20 16:00:00"},{"startDateTime":"2023-11-20 16:00:00","endDateTime":"2023-11-20 18:00:00"},{"startDateTime":"2023-11-20 18:00:00","endDateTime":"2023-11-20 20:00:00"},{"startDateTime":"2023-11-20 20:00:00","endDateTime":"2023-11-20 22:00:00"}],"2023-11-21 00:00:00":[{"startDateTime":"2023-11-21 14:00:00","endDateTime":"2023-11-21 16:00:00"},{"startDateTime":"2023-11-21 16:00:00","endDateTime":"2023-11-21 18:00:00"},{"startDateTime":"2023-11-21 18:00:00","endDateTime":"2023-11-21 20:00:00"},{"startDateTime":"2023-11-21 20:00:00","endDateTime":"2023-11-21 22:00:00"}],"2023-11-22 00:00:00":[{"startDateTime":"2023-11-22 14:00:00","endDateTime":"2023-11-22 16:00:00"},{"startDateTime":"2023-11-22 16:00:00","endDateTime":"2023-11-22 18:00:00"},{"startDateTime":"2023-11-22 18:00:00","endDateTime":"2023-11-22 20:00:00"},{"startDateTime":"2023-11-22 20:00:00","endDateTime":"2023-11-22 22:00:00"}],"2023-11-23 00:00:00":[{"startDateTime":"2023-11-23 14:00:00","endDateTime":"2023-11-23 16:00:00"},{"startDateTime":"2023-11-23 16:00:00","endDateTime":"2023-11-23 18:00:00"},{"startDateTime":"2023-11-23 18:00:00","endDateTime":"2023-11-23 20:00:00"},{"startDateTime":"2023-11-23 20:00:00","endDateTime":"2023-11-23 22:00:00"}],"2023-11-24 00:00:00":[{"startDateTime":"2023-11-24 14:00:00","endDateTime":"2023-11-24 16:00:00"},{"startDateTime":"2023-11-24 16:00:00","endDateTime":"2023-11-24 18:00:00"},{"startDateTime":"2023-11-24 18:00:00","endDateTime":"2023-11-24 20:00:00"},{"startDateTime":"2023-11-24 20:00:00","endDateTime":"2023-11-24 22:00:00"}],"2023-11-27 00:00:00":[{"startDateTime":"2023-11-27 14:00:00","endDateTime":"2023-11-27 16:00:00"},{"startDateTime":"2023-11-27 16:00:00","endDateTime":"2023-11-27 18:00:00"},{"startDateTime":"2023-11-27 18:00:00","endDateTime":"2023-11-27 20:00:00"},{"startDateTime":"2023-11-27 20:00:00","endDateTime":"2023-11-27 22:00:00"}],"2023-11-28 00:00:00":[{"startDateTime":"2023-11-28 14:00:00","endDateTime":"2023-11-28 16:00:00"},{"startDateTime":"2023-11-28 16:00:00","endDateTime":"2023-11-28 18:00:00"},{"startDateTime":"2023-11-28 18:00:00","endDateTime":"2023-11-28 20:00:00"},{"startDateTime":"2023-11-28 20:00:00","endDateTime":"2023-11-28 22:00:00"}],"2023-11-29 00:00:00":[{"startDateTime":"2023-11-29 14:00:00","endDateTime":"2023-11-29 16:00:00"},{"startDateTime":"2023-11-29 16:00:00","endDateTime":"2023-11-29 18:00:00"},{"startDateTime":"2023-11-29 18:00:00","endDateTime":"2023-11-29 20:00:00"},{"startDateTime":"2023-11-29 20:00:00","endDateTime":"2023-11-29 22:00:00"}],"2023-11-30 00:00:00":[{"startDateTime":"2023-11-30 14:00:00","endDateTime":"2023-11-30 16:00:00"},{"startDateTime":"2023-11-30 16:00:00","endDateTime":"2023-11-30 18:00:00"},{"startDateTime":"2023-11-30 18:00:00","endDateTime":"2023-11-30 20:00:00"},{"startDateTime":"2023-11-30 20:00:00","endDateTime":"2023-11-30 22:00:00"}]}"""
print(list(accept_suggested_timings))
a = json.loads(accept_suggested_timings)
b = list(a)
print(b)
字符串
有没有办法把string转换成json?
Required solution: [ {"2023-11-20 00:00:00":[{"startDateTime":"2023-11-20 14:00:00","endDateTime":"2023-11-20 16:00:00"},{"startDateTime":"2023-11-20 16:00:00","endDateTime":"2023-11-20 18:00:00"},{"startDateTime":"2023-11-20 18:00:00","endDateTime":"2023-11-20 20:00:00"},{"startDateTime":"2023-11-20 20:00:00","endDateTime":"2023-11-20 22:00:00"}],"2023-11-21 00:00:00":[{"startDateTime":"2023-11-21 14:00:00","endDateTime":"2023-11-21 16:00:00"},{"startDateTime":"2023-11-21 16:00:00","endDateTime":"2023-11-21 18:00:00"},{"startDateTime":"2023-11-21 18:00:00","endDateTime":"2023-11-21 20:00:00"},{"startDateTime":"2023-11-21 20:00:00","endDateTime":"2023-11-21 22:00:00"}],"2023-11-22 00:00:00":[{"startDateTime":"2023-11-22 14:00:00","endDateTime":"2023-11-22 16:00:00"},{"startDateTime":"2023-11-22 16:00:00","endDateTime":"2023-11-22 18:00:00"},{"startDateTime":"2023-11-22 18:00:00","endDateTime":"2023-11-22 20:00:00"},{"startDateTime":"2023-11-22 20:00:00","endDateTime":"2023-11-22 22:00:00"}],"2023-11-23 00:00:00":[{"startDateTime":"2023-11-23 14:00:00","endDateTime":"2023-11-23 16:00:00"},{"startDateTime":"2023-11-23 16:00:00","endDateTime":"2023-11-23 18:00:00"},{"startDateTime":"2023-11-23 18:00:00","endDateTime":"2023-11-23 20:00:00"},{"startDateTime":"2023-11-23 20:00:00","endDateTime":"2023-11-23 22:00:00"}],"2023-11-24 00:00:00":[{"startDateTime":"2023-11-24 14:00:00","endDateTime":"2023-11-24 16:00:00"},{"startDateTime":"2023-11-24 16:00:00","endDateTime":"2023-11-24 18:00:00"},{"startDateTime":"2023-11-24 18:00:00","endDateTime":"2023-11-24 20:00:00"},{"startDateTime":"2023-11-24 20:00:00","endDateTime":"2023-11-24 22:00:00"}],"2023-11-27 00:00:00":[{"startDateTime":"2023-11-27 14:00:00","endDateTime":"2023-11-27 16:00:00"},{"startDateTime":"2023-11-27 16:00:00","endDateTime":"2023-11-27 18:00:00"},{"startDateTime":"2023-11-27 18:00:00","endDateTime":"2023-11-27 20:00:00"},{"startDateTime":"2023-11-27 20:00:00","endDateTime":"2023-11-27 22:00:00"}],"2023-11-28 00:00:00":[{"startDateTime":"2023-11-28 14:00:00","endDateTime":"2023-11-28 16:00:00"},{"startDateTime":"2023-11-28 16:00:00","endDateTime":"2023-11-28 18:00:00"},{"startDateTime":"2023-11-28 18:00:00","endDateTime":"2023-11-28 20:00:00"},{"startDateTime":"2023-11-28 20:00:00","endDateTime":"2023-11-28 22:00:00"}],"2023-11-29 00:00:00":[{"startDateTime":"2023-11-29 14:00:00","endDateTime":"2023-11-29 16:00:00"},{"startDateTime":"2023-11-29 16:00:00","endDateTime":"2023-11-29 18:00:00"},{"startDateTime":"2023-11-29 18:00:00","endDateTime":"2023-11-29 20:00:00"},{"startDateTime":"2023-11-29 20:00:00","endDateTime":"2023-11-29 22:00:00"}],"2023-11-30 00:00:00":[{"startDateTime":"2023-11-30 14:00:00","endDateTime":"2023-11-30 16:00:00"},{"startDateTime":"2023-11-30 16:00:00","endDateTime":"2023-11-30 18:00:00"},{"startDateTime":"2023-11-30 18:00:00","endDateTime":"2023-11-30 20:00:00"},{"startDateTime":"2023-11-30 20:00:00","endDateTime":"2023-11-30 22:00:00"}]} ]
2条答案
按热度按时间lb3vh1jj1#
你可以使用list comprehension来实现:
代码:
字符串
检查output here
x8goxv8g2#
如果你只是想要日期,检查这个:
字符串
output of the code