如何在python请求中发布以null为值的JSON数据

时间:2018-11-10 11:44:34

标签: python json post

我有JSON数据,需要格式化并将其发送到服务器,并将null值设置为null。 Python中的字典不能将null作为值,而可以将“ null”作为值。如何将以上内容转换为Python可以识别的字典?

a = {"name":"p_retailprice","type":"DOUBLE","comment":"","precision":null,"scale":null}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'null' is not defined

1 个答案:

答案 0 :(得分:3)

Python中null关键字的等效项为None。

尝试

a = {"name":"p_retailprice","type":"DOUBLE","comment":"","precision":None,"scale":None}