第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python從請求響應中獲取第一項

Python從請求響應中獲取第一項

慕蓋茨4494581 2023-03-08 16:27:08
我正在使用這樣的 python 請求查詢 API...url = "www.example.com"response = requests.request("POST", url)response--------[  {    "id": "485744",    "descript": "firstitem",  },  {    "id": "635456",    "descript": "seconditem",  },  {    "id": "765554",    "descript": "thirditem",  },]我正在嘗試像這樣訪問響應中的第一項...response = response.jsonprint(response[0])但我收到錯誤...TypeError: 'method' object is not subscriptable我哪里錯了?
查看完整描述

2 回答

?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

json是類的方法Response而不是對象的屬性。要獲取 json 數據,請使用:

response = response.json()


查看完整回答
反對 回復 2023-03-08
?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

你沒有正確地稱呼它:response.json()


替代方法:


import json #import this on the top

response = json.loads(response) #You need to load the data into JSON

還:每個末尾的附加逗號 (,) "descript":


"firstitem", "seconditem","thirditem"不是必需的,可能會出錯。


查看完整回答
反對 回復 2023-03-08
  • 2 回答
  • 0 關注
  • 133 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號