美文网首页
Python 整齐的输出

Python 整齐的输出

作者: JaiUnChat | 来源:发表于2016-11-23 14:13 被阅读157次

带缩进格式JSON

直接上代码
json.dumps()官网文档

jsonDict = '{"name":{"nickName": "null", "realName": "No"},"age":"00"}' // str
jsonObject = json.loads(jsonDict) // json对象
jsonStr = json.dumps(jsonObject, indent=1) // json对象转json格式字符串关键是这一句的indent参数
print(jsonStr) 
# 输出
{
 "age": "00",
 "name": {
  "nickName": "null",
  "realName": "No"
 }
}

相关文章

网友评论

      本文标题:Python 整齐的输出

      本文链接:https://www.haomeiwen.com/subject/fvtvpttx.html