Object of type datetime is not JSON serializable
#解决datetime.datetime is not JSON serializable
class JsonDateEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.strftime('%Y-%m-%d %H:%M:%S')
elif isinstance(obj, date):
return obj.strftime("%Y-%m-%d")
else:
return json.JSONEncoder.default(self, obj)
allcontent = {xxx}
print(json.dumps({'status': 200, 'data': allcontent}, cls=JsonDateEncoder)
转载请注明:IPCPU-网络之路 » 解决datetime.datetime is not JSON serializable