class DateEncoder(json.JSONEncoder): def default(self, obj): if hasattr(obj, 'isoformat'): return obj.isoformat() else: return str(obj) return json.JSONEncoder.default(self, obj) json.dumps(my_variable, cls=DateEncoder)
References :
python - Cannot serialize datetime as JSON from Cherrypy - Stack Overflow
沒有留言:
張貼留言