class JsonCustomEncoder(json.JSONEncoder): def default(self, field): if isinstance(field,datetime): return field.strftime('%Y-%m-%d %H:%M:%S') elif isinstance(field,date): return field.strftime('%Y-%m-%d') elif isinstance(field, decimal.Decimal): return float(field) else: return json.JSONEncoder.default(self,field)
json.dums(你的数据, cls=JsonCustomEncoder)