您当前的位置: 首页 >  Python

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

彭世瑜 发布时间:2018-07-04 11:50:25 ,浏览量:3

代码:

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

关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 3浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0524s