我在文件中有这个JSON:
[
{
"contributors": null,
"coordinates": null,
"created_at": "Fri Aug 04 21:12:59 +0000 2017",
"entities": {
"hashtags": [],
"media": [
{
"display_url": "pic.twitter.com",
"expanded_url": "https://twitter.com",
"id": 893569740,
"id_str": "893027840",
"indices": [
16,
39
],
"media_url": "http://pbs.tw.com/media",
"media_url_https": "https://pbs.twimg.com/media/1.jpg",
"sizes": {
"large": {
"h": 581,
"resize": "fit",
"w": 400
}
},
"source_status_id": 20925697,
"url": "https://ca.com"
}
]
},
"id": 343288
}
]
我写了这个脚本,它打印了所有的json文本:
with open('tweets.json') as json_data:
data = json.load(json_data)
print (data)
如何使用Python解析文件并计算JSON文件中存在的ID数量?