gpt4 book ai didi

javascript - OpenWeatherMap API 仅预测几天

转载 作者:行者123 更新时间:2023-12-02 21:58:59 28 4
gpt4 key购买 nike

问题是当我获取 URL 来获取预测的 JSON 文件时,它给了我一个 40 对象的数组(每 3 小时预测一次,持续 5 天),现在我只想显示每日预报,而非每 3 小时预报。

我怎样才能用 JavaScript 做到这一点?

数组:

{…}

city: Object { id: 2643743, name: "London", country: "GB", … }

cnt: 40

cod: "200"

list: (40) […]
​​
0: Object { dt: 1580148000, main: {…}, dt_txt: "2020-01-27 18:00:00", … }
​​
1: Object { dt: 1580158800, main: {…}, dt_txt: "2020-01-27 21:00:00", … }
​​
2: Object { dt: 1580169600, main: {…}, dt_txt: "2020-01-28 00:00:00", … }
​​
3: Object { dt: 1580180400, main: {…}, dt_txt: "2020-01-28 03:00:00", … }
​​
4: Object { dt: 1580191200, main: {…}, dt_txt: "2020-01-28 06:00:00", … }
​​
5: Object { dt: 1580202000, main: {…}, dt_txt: "2020-01-28 09:00:00", … }
​​
6: Object { dt: 1580212800, main: {…}, dt_txt: "2020-01-28 12:00:00", … }
​​
7: Object { dt: 1580223600, main: {…}, dt_txt: "2020-01-28 15:00:00", … }
​​
8: Object { dt: 1580234400, main: {…}, dt_txt: "2020-01-28 18:00:00", … }
​​
9: Object { dt: 1580245200, main: {…}, dt_txt: "2020-01-28 21:00:00", … }
​​
10: Object { dt: 1580256000, main: {…}, dt_txt: "2020-01-29 00:00:00", … }
​​
11: Object { dt: 1580266800, main: {…}, dt_txt: "2020-01-29 03:00:00", … }
​​
12: Object { dt: 1580277600, main: {…}, dt_txt: "2020-01-29 06:00:00", … }
​​
13: Object { dt: 1580288400, main: {…}, dt_txt: "2020-01-29 09:00:00", … }
​​
14: Object { dt: 1580299200, main: {…}, dt_txt: "2020-01-29 12:00:00", … }
​​
15: Object { dt: 1580310000, main: {…}, dt_txt: "2020-01-29 15:00:00", … }
​​
16: Object { dt: 1580320800, main: {…}, dt_txt: "2020-01-29 18:00:00", … }
​​
17: Object { dt: 1580331600, main: {…}, dt_txt: "2020-01-29 21:00:00", … }
​​
18: Object { dt: 1580342400, main: {…}, dt_txt: "2020-01-30 00:00:00", … }
​​
19: Object { dt: 1580353200, main: {…}, dt_txt: "2020-01-30 03:00:00", … }
​​
20: Object { dt: 1580364000, main: {…}, dt_txt: "2020-01-30 06:00:00", … }
​​
21: Object { dt: 1580374800, main: {…}, dt_txt: "2020-01-30 09:00:00", … }
​​
22: Object { dt: 1580385600, main: {…}, dt_txt: "2020-01-30 12:00:00", … }
​​
23: Object { dt: 1580396400, main: {…}, dt_txt: "2020-01-30 15:00:00", … }
​​
24: Object { dt: 1580407200, main: {…}, dt_txt: "2020-01-30 18:00:00", … }
​​
25: Object { dt: 1580418000, main: {…}, dt_txt: "2020-01-30 21:00:00", … }
​​
26: Object { dt: 1580428800, main: {…}, dt_txt: "2020-01-31 00:00:00", … }
​​
27: Object { dt: 1580439600, main: {…}, dt_txt: "2020-01-31 03:00:00", … }
​​
28: Object { dt: 1580450400, main: {…}, dt_txt: "2020-01-31 06:00:00", … }
​​
29: Object { dt: 1580461200, main: {…}, dt_txt: "2020-01-31 09:00:00", … }
​​
30: Object { dt: 1580472000, main: {…}, dt_txt: "2020-01-31 12:00:00", … }
​​
31: Object { dt: 1580482800, main: {…}, dt_txt: "2020-01-31 15:00:00", … }
​​
32: Object { dt: 1580493600, main: {…}, dt_txt: "2020-01-31 18:00:00", … }
​​
33: Object { dt: 1580504400, main: {…}, dt_txt: "2020-01-31 21:00:00", … }
​​
34: Object { dt: 1580515200, main: {…}, dt_txt: "2020-02-01 00:00:00", … }
​​
35: Object { dt: 1580526000, main: {…}, dt_txt: "2020-02-01 03:00:00", … }
​​
36: Object { dt: 1580536800, main: {…}, dt_txt: "2020-02-01 06:00:00", … }
​​
37: Object { dt: 1580547600, main: {…}, dt_txt: "2020-02-01 09:00:00", … }
​​
38: Object { dt: 1580558400, main: {…}, dt_txt: "2020-02-01 12:00:00", … }
​​
39: Object { dt: 1580569200, main: {…}, dt_txt: "2020-02-01 15:00:00", … }
​​
length: 40
​​
<prototype>: Array []

message: 0

<prototype>: Object { … }
weather.js:78:11

而且我需要它与用户获取数据的日期无关。

我使用的是 openweathermap 的免费版本。

最佳答案

那么您使用的 api 类型不正确。试试这个

api.openweathermap.org/data/2.5/forecast/daily?q=London&mode=xml&units=metric&cnt=7

link here

关于javascript - OpenWeatherMap API 仅预测几天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59935038/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com