【发布时间】:2020-04-09 06:22:42
【问题描述】:
所以我有一些问题要找到如何从 JSON 列表中打印一个干净的字符串 // Dict 文件。 我尝试了 .join、.split 方法,但它似乎不起作用。谢谢大家的帮助
我的代码:
import json
with open("user.json") as f:
data = json.load(f)
for person in data["person"]:
print(person)
JSON 文件
{
"person": [
{
"name": "Peter",
"Country": "Montreal",
"Gender": "Male"
},
{
"name": "Alex",
"Country": "Laval",
"Gender": "Male"
}
]
}
打印输出(这不是我想要的正确格式)
{'name': 'Peter', 'Country': 'Montreal', 'Gender': 'Male'}
{'name': 'Alex', 'Country': 'Laval', 'Gender': 'Male'}
我希望输出打印格式是这样的:
Name: Peter
Country: Montreal
Gender:Male
【问题讨论】:
标签: python json string list dictionary