python, datetime is not json serializable
import datetime
def json_serial(obj): """JSON serializer for objects not serializable by default json code""" if isinstance(obj, (datetime.datetime, datetime.date)): return obj.isoformat() raise TypeError("Type %s not serializable" % type(obj))
示例代码:
from datetime import datetime from json import dumps print dumps(datetime.now(), default=json_serial)
ref:https://stackoverflow.com/questions/11875770/how-to-overcome-datetime-datetime-not-json-serializable