【发布时间】:2020-08-09 21:40:40
【问题描述】:
我无法解析我在 python 中的响应,感谢任何关于我需要更改的反馈!
url = 'https://someURL'
headers = {'Authorization' : 'Bearer <MyToken>'}
r = requests.get(url, headers=headers)
#This part prints entire response content in a text like format [{'x':'' ,'y':'', ...etc},{'x':'' ,'y':'', ...etc},...etc]
jsonResponse = r.json()
print("Entire JSON response")
print(jsonResponse)
# when I try to parse into each item and get the key value, I get an error
print("Print each key-value pair from JSON response")
for key, value in jsonResponse.items():
print(key, ":", value)
这是我得到的错误
Traceback (most recent call last):
File "blueiInitialSync.py", line 131, in <module>
for key, value in jsonResponse.items():
AttributeError: 'list' object has no attribute 'items'
bash: parse_git_branch: command not found
【问题讨论】:
-
jsonResponse的类型为list。试试for key, value in jsonResponse[0].items():
标签: python httprequest httpresponse