python-TypeError: Object of type 'datetime' is not JSON serializable 报错

class CJsonEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime.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)
j = json.dumps(xxxxxxxxxx,cls=CJsonEncoder)

你可能感兴趣的:(python)