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类型

转载自:https://blog.csdn.net/mouday/article/details/80910275

You may also like...