python编程:json indent can't multiply sequence by non-int of type 'str'

代码:

print(json.dumps({"key": "value"}, indent="\t"))

问题:

json indent can't multiply sequence by non-int of type 'str'

借助百度翻译:

JSON缩进不能用“STR”类型的非int乘以序列

参看json的dumps实现也没指明类型,隐约看到integer,修改代码如下

print(json.dumps({"key": "value"}, indent=4))

成功dump

{
    "key": "value"
}

总结:

python 的 json.dumps() 参数 indent 需要传入一个 int类型

上一篇:宇宙射线会导致路由器故障 思科你是认真的吗?


下一篇:Mellanox推出基于6WIND的路由器和平台