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

class DecimalEncoder(json.JSONEncoder):

    def default(self, o):

        if isinstance(o, decimal.Decimal):
            return float(o)

        super(DecimalEncoder, self).default(o)
j = json.dumps(xxxxxxx,cls=DecimalEncoder)

你可能感兴趣的:(python)