使用Python解析JSON?

2024-10-02 08:24:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用githubapi来获取关于存储库上提交的JSON数据。你知道吗

链接到JSON文件:https://api.github.com/repos/ErinBailey/cs399-social/commits

我正在尝试获取所有致力于某个项目的用户的“id”。我该怎么做呢?现在我看到JSON文件的结构是sha/author/id

到目前为止,我的代码是:

r = requests.get('https://api.github.com/repos/ErinBailey/cs399-social/commits', auth=('cs399contributions', 'contributions399'))

input_log = json.loads(r.text)
print(json.dumps(input_log, indent=4))
user_ids = [x for x in input_log if x['sha/commit/author/id'] > '0']
output_json = json.dumps(user_ids,indent=4)
print output_json

Tags: 文件httpsgithubcomlogapiidjson
1条回答
网友
1楼 · 发布于 2024-10-02 08:24:24

这是我的密码。你知道吗

import requests
import json

r = requests.get('https://api.github.com/repos/ErinBailey/cs399-social/commits',
                 auth=('cs399contributions', 'contributions399'))

input_log = json.loads(r.text)
user_ids = [x['committer']['id'] for x in input_log if x['committer'].get('id')]
output_json = json.dumps(user_ids, indent=4)
print output_json

相关问题 更多 >

    热门问题