我想使用python呼叫天氣api的描述,但是當我輸入代碼時它給了我這個錯誤,但我到處搜索卻看不到它。
這是代碼
des = response['weather']['description']
print("Description = ",des)
但我收到這個錯誤
TypeError:串列索引必須是整數或切片,而不是 str
uj5u.com熱心網友回復:
使用它可以解決它:
des = response['weather'][0]['description'][0]
print("Description = ",des)
希望這可以幫助!
筆記:
下次將您的 JSON 代碼添加到帖子中以使事情變得更容易。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/484851.html
