TypeError: Decimal('84.3333333333333333') is not JSON serializable
你应该用的是dumps()这个函数吧?
这个错误是指你的变量不能转换成JSON字符串,你的变量不符合JSON的格式。
解决办法:
import json
from decimal import Decimal
def default(obj):
if isinstance(obj, Decimal):
return str(obj)
raise TypeError("Object of type '%s' is not JSON serializable" % type(obj).__name__)
json.dumps(testlist, default=default)
Be good all the time

浙公网安备 33010602011771号