您的位置:首页 > 编程语言 > Python开发

Python字典的json格式化处理

2016-01-19 19:26 627 查看
Prefer = {"jim": {"War": 1.9, "the big bang": 1.0, "The lord of wings": 4.0, "Beautiful America": 4.7}, "lily": {"War": 2.0, "Kongfu": 4.1, "The lord of wings": 3.6}, "tommy": {"War": 2.3, "Kongfu": 5.0, "The lord of wings": 3.0}, "jack": {"War": 2.8, "Kongfu": 5.5, "The lord of wings": 3.5}}
print('将字典一行显示不换行')
print(json.dumps(Prefer))
print('将字典按照json样式可视化显示')
print(json.dumps(Prefer,indent=1))

显示的结果是:

将字典一行显示不换行
{"jim": {"War": 1.9, "the big bang": 1.0, "The lord of wings": 4.0, "Beautiful America": 4.7}, "lily": {"War": 2.0, "Kongfu": 4.1, "The lord of wings": 3.6}, "tommy": {"War": 2.3, "Kongfu": 5.0, "The lord of wings": 3.0}, "jack": {"War": 2.8, "Kongfu": 5.5, "The lord of wings": 3.5}}
将字典按照json样式可视化显示
{
"jim": {
"War": 1.9,
"the big bang": 1.0,
"The lord of wings": 4.0,
"Beautiful America": 4.7
},
"lily": {
"War": 2.0,
"Kongfu": 4.1,
"The lord of wings": 3.6
},
"tommy": {
"War": 2.3,
"Kongfu": 5.0,
"The lord of wings": 3.0
},
"jack": {
"War": 2.8,
"Kongfu": 5.5,
"The lord of wings": 3.5
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: