string - 使用 Open Weather Map 每小时数据
问题描述
Open Weather Map 是一个开源天气提供者,并且有一个 API 可以提供接下来 2 天的每小时天气数据,因此有 48 个数据点。它将数据作为对象返回,并如下所示进行设置。
{
"hourly": [
{
"dt": 1631725200,
"temp": 16.75,
"feels_like": 16.33,
"pressure": 1014,
"humidity": 71,
"dew_point": 11.47,
"uvi": 0,
"clouds": 20,
"visibility": 10000,
"wind_speed": 3.33,
"wind_deg": 88,
"wind_gust": 7.37,
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "few clouds",
"icon": "02d"
}
],
"pop": 0
},
....
}
我想从每个小时获取温度,并尝试通过循环循环来完成它,但它作为一个字符串返回并在一个长字符串中返回所有 48 个温度。weatherResponse 部分是使用 axios 调用 api 的 const。
let hourlyTemp = [];
for (let i = 1; i < 48; i++) {
hourlyTemp += [weatherResponse.data.hourly[i].temp] + " °C " + "<br>"
}
是否有不同的方法来编写循环,使其以对象或数组的形式返回?或者有没有办法在之后拆分字符串?
非常感谢!
解决方案
推荐阅读
- flutter - 显示包的所有图标
- sql - 如何在 Access VBA 中运行双循环
- elasticsearch - Elasticsearch 查询从不一致的逗号分隔值数组中删除删除值
- linux - 如何启用远程连接以使用 PostgreSQL?
- many-to-many - 具有多对多关系的 PowerBI
- node.js - 将 ASCII 转换为 Base64,然后使用 NodeJS 转换为二进制
- github-actions - 如何使用 GitHub Actions 访问 GitHub 问题评论正文?
- powershell - 如何根据数据来自的月份将 powershell 中的数据附加到不同的文件中?
- python - NameError:未定义名称“print_rows”
- listview - Xamarin.Forms ListView 不突出显示所选项目?