python json.dumps Decimal问题

1. https://www.cnblogs.com/sunqim16/p/10755054.html

class DecimalEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, decimal.Decimal):
            return float(o)
        super(DecimalEncoder, self).default(o)
json.dumps(ext, cls=DecimalEncoder, ensure_ascii=False)

 

posted @ 2020-08-27 14:45  jackduan1  阅读(718)  评论(0编辑  收藏  举报