如何在python中打印从github接收到的json对象中的所有可用消息?

oyxsuwqo  于 2022-11-19  发布在  Python
关注(0)|答案(2)|浏览(132)

我收到了一个json对象,它显示了github repo上两个标签之间的比较。我想显示JSON对象中所有可用的消息。json对象可以在这里看到:https://api.github.com/repos/git/git/compare/v2.37.4...v2.38.1
我使用了python中的requests库来接收对象:

import requests
response= requests.get('https://api.github.com/repos/git/git/compare/v2.37.4...v2.38.1')
json_obj=response.json()

现在我如何打印json对象中每个名为'message'的属性示例的值?

dxxyhpgq

dxxyhpgq1#

这个会有帮助

import requests
response= requests.get('https://api.github.com/repos/git/git/compare/v2.37.4...v2.38.1')
json_obj=response.json()
for i in json_obj.keys():
    print(i , json_obj[i])  #  there i is for the the key and json_obj[i] gives the value at the key
print(json_obj["base_commit"]['commit']['message']) # will print the message
8fq7wneg

8fq7wneg2#

这将打印JSON响应中每个提交的消息。

import requests

response = requests.get('https://api.github.com/repos/git/git/compare/v2.37.4...v2.38.1')
json_obj = response.json()

for commit in json_obj['commits']:
    print(commit['commit']['message'])

相关问题