首先,我想问一个典型的多对象JSON文件格式是什么?在
它是一个对象列表,比如:[ {...}, {...} ... ]
?在
其次,我尝试使用python将多个dict
存储到单个JSON
文件中。在
我有两个理由:
test_data = {'profile_img': 'https://fmdataba.com/images/p/4592.png',
'name': 'Son Heung-Min ',
'birth_date': '8/7/1992',
'nation': 'South Korea KOR',
'position': 'M (R), AM (RL), ST (C)',
'foot': 'Either'}
以及
^{pr2}$然后我做了
with open('data.json', 'w') as json_file:
json.dump(test_data, json_file, indent=2)
json.dump(test_data2, json_file, indent=2)
当然,我会迭代一个dict
的列表来存储多个dict
,但我现在只是这样做以测试格式是否正确。结果.json
文件如下所示
数据.json
{
"profile_img": "https://fmdataba.com/images/p/4592.png",
"name": "Son Heung-Min ",
"birth_date": "8/7/1992",
"nation": "South Korea KOR",
"position": "M (R), AM (RL), ST (C)",
"foot": "Either"
}{
"profile_img": "https://fmdataba.com/images/p/1103.png",
"name": "Marc-Andr\u00e9 ter Stegen ",
"birth_date": "30/4/1992",
"nation": "Germany",
"position": "GK",
"foot": "Either"
}
这看起来很奇怪,因为两个对象之间没有,
。
典型的做法是什么?在
你需要创建一个对象来保存列表中的所有日期首先。然后将此列表转储到文件。在
相关问题 更多 >
编程相关推荐