你应该用的是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)