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)

 

 

 

posted @ 2018-01-27 15:07  潘多拉Pandora  阅读(825)  评论(0)    收藏  举报