str1 = { "name":"laowang", "age":18, "heighet":"haha", "brand":{"name":2} } import json print(json.dumps(str1)) 结果: {"brand": {"name": 2}, "heighet": "haha", "age": 18, "name": "laowang"} print(json.dumps(str1,indent=2,sort_keys=True)) 结果: { "age": 18, "brand": { "name": 2 }, "heighet": "haha", "name": "laowang" } # 这种可以很方便查看
python json.dumps 格式化输入
最新推荐文章于 2024-10-12 09:58:15 发布