代碼:
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類型