如何在Python请求中以null作为值发布JSON数据

Dha*_*ngh 7 python post json

我有 JSON 数据,需要对其进行格式化并将空值设置为 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
Run Code Online (Sandbox Code Playgroud)

Par*_*ngh 8

Python 中 null 关键字的等价物是 None。

尝试

a = {"name":"p_retailprice","type":"DOUBLE","comment":"","precision":None,"scale":None}
Run Code Online (Sandbox Code Playgroud)