JSON.Loads()TypeError:类型对象'十进制'不是JSON可序列化的。 Python 3.6

时间:2018-02-27 15:16:31

标签: json python-3.x decimal

我试图让JSON在API的帖子中解析精确的小数。我一直遇到这个错误:TypeError:类型' Decimal'的对象不是JSON可序列化的。 理想情况下,我想在本文中使用它的方式而不是编写自定义解码器:http://www.daveoncode.com/2014/10/21/python-reading-numbers-from-json-without-loss-of-precision-using-decimal-class-for-data-processing/

这是我发的帖子:

getcontext().prec = 6
fdecimal = json.loads(dict["decimalnum"], parse_int=Decimal, parse_float=Decimal)

if (a > z):
                xpost = {"x":"y",
                    "f":fdecimal}
                rpost = requests.post(api_url + "xpost", json=xpost, auth=auth)
                print(rpost.json())
elif (a < z):
                xpost = {"x":"y",
                    "f":fdecimal}
                rpost = requests.post(api_url + "xpost", json=xpost, auth=auth)
                print(rpost.json())

我尝试了很多不同的东西,但仍然无法弄明白。非常感谢帮助!谢谢!

0 个答案:

没有答案
相关问题