我明白了
{"coord":{"lon":116.3972,"lat":39.9075},"weather":[{"id":800,"main":"Ясно","description":"ясное небо","icon ":"01d"}],"base":"stations","main":{"temp":10.94,"feels_like":8.48,"temp_min":10.94,"temp_max":10.94,"pressure":1013 ,"humidity":15,"sea_level":1013,"grnd_level":1007},"visibility":10000,"wind":{"speed":1,89,"deg":234,"gust":3,45}, "clouds":{"all":4},"dt":1709371712,"sys":{"type":1,"id":9609,"country":"CN","sunrise":1709333188," закат":1709374019},"часовой пояс":28800,"id":1816670,"name":"Пекин","cod":200}
你需要在这里得到它
"weather":[{"id":800,"main":"Ясно","description":"ясное небо","icon ":"01d"}]
这是通过 python JSON 库实现的。如果你写
res = requests.get(f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid={API}&units=metric')
data = json.loads(res.text)
data["weather"]["description"]
然后它显示一个错误:TypeError: list indices must be integers or slices, not str