Javascript 如何从api中的对象中的数组中获取数据
我使用OpenWeatherMapAPI创建了一个简单的天气应用程序。模式如下:Javascript 如何从api中的对象中的数组中获取数据,javascript,arrays,json,api,fetch,Javascript,Arrays,Json,Api,Fetch,我使用OpenWeatherMapAPI创建了一个简单的天气应用程序。模式如下: { "coord": { "lon": -122.08, "lat": 37.39 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01d" } ], "base": "stations", "m
{
"coord": {
"lon": -122.08,
"lat": 37.39
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "stations",
"main": {
"temp": 282.55,
"feels_like": 281.86,
"temp_min": 280.37,
"temp_max": 284.26,
"pressure": 1023,
"humidity": 100
}...
我试图访问包含数组的weather键中的值。这就是我所尝试的:
let iconImage = '';
data.weather.map((description, icon) => {
this.description.textContent += description;
iconImage += icon;
});
this.icon.setAttribute('src', data.weather.icon);
说明和图标是指向html代码中li元素的变量,我从API获取的数据应该输入这些元素
我该如何以正确的方式进行此操作
let数据={
“合作社”:{
“lon”:-122.08,
“lat”:37.39
},
“天气”:[
{
“id”:800,
“主要”:“明确”,
“说明”:“晴朗的天空”,
“图标”:“01d”
}
],
“基站”:“基站”,
“主要”:{
“温度”:282.55,
“感觉像”:281.86,
“最低温度”:280.37,
“最高温度”:284.26,
“压力”:1023,
“湿度”:100
}
};
console.log(data.weather[0].图标)代码>用于获取描述@Alessio Cantarella