标签:col def ret from stat sel response time __init__
import json from datetime import date from datetime import datetime class JsonCustomEncoder(json.JSONEncoder): def default(self, field): if isinstance(field, datetime): return field.strftime(‘%Y-%m-%d %H‘) elif isinstance(field, date): return field.strftime(‘%Y-%m-%d‘) elif isinstance(field, Response): return field.__dict__ else: return json.JSONEncoder.default(self, field) class Response(object): def __init__(self): self.status =True self.data = "asdf" data = { ‘k1‘: 123, ‘k2‘: datetime.now(), ‘k3‘: Response() } ds = json.dumps(data, cls=JsonCustomEncoder) print(ds)
标签:col def ret from stat sel response time __init__
原文地址:https://www.cnblogs.com/master-song/p/9497399.html