想獲得漂亮的格式化字符串后輸出,可以使用json.dumps() 的indent 參數。它會使得輸出和pprint() 函數效果類似
>>> data
{'age': 4, 'name': 'niuniuche', 'attribute': 'toy'}
>>> import json
>>> print(json.dumps(data))
{"age": 4, "name": "niuniuche", "attribute": "toy"}
>>> print(json.dumps(data,indent=3))
{
"age": 4,
"name": "niuniuche",
"attribute": "toy"
}
>>>
