【问题标题】:Data returned from open weather map API not making sense从开放天气图 API 返回的数据没有意义
【发布时间】:2013-10-03 18:56:54
【问题描述】:

我正在使用Open Weather Map API。我还在玩电话。我正在查看 2 个特定调用的结果。一个用于London,另一个用于South Africa 中的Hermanus。我观察到,并非 Hermanus 调用中返回的所有数据都包含在 London 调用中返回的数据中。

这是我的两个电话:

返回伦敦的数据是:

{
     "coord": {
          "lon":-0.12574,
          "lat":51.50853
     },
     "sys": {
          "country":"GB",
          "sunrise":1380261352,
          "sunset":1380303998
     },
     "weather": [{
          "id":800,
          "main":"Clear",
          "description":"Sky is Clear",
          "icon":"01d"
     }],
     "base":"gdps stations",
     "main": {
          "temp":290.22,
          "pressure":1016,
          "humidity":63,
          "temp_min":289.15,
          "temp_max":291.48
     },
     "wind": {
          "speed":6.2,
          "deg":100
     },
     "clouds": {
          "all":0
     },
     "dt":1380285272,
     "id":2643743,
     "name":"London",
     "cod":200
}

而为 Hermanus 返回的数据是:

{
     "coord": {
          "lon":19.234461,
          "lat":-34.418701
     },
     "sys": {
          "country":"ZA",
          "sunrise":1380255856,
          "sunset":1380300203
     },
     "weather": [{
          "id":804,
          "main":"Clouds",
          "description":"overcast clouds",
          "icon":"04d"
     }],
     "base":"gdps stations",
     "main": {
          "temp":284.981,
          "temp_min":284.981,
          "temp_max":284.981,
          "pressure":999.07,
          "sea_level":1026.12,
          "grnd_level":999.07,
          "humidity":77
     },
     "wind": {
          "speed":6.71,
          "deg":282
     },
     "rain": {
          "3h":0
     },
     "clouds": {
          "all":92
     },
     "dt":1380285425,
     "id":3366880,
     "name":"Hermanus",
     "cod":200
}

为什么一个包含某些数据而另一个不包含?我怎样才能找出可以从这样的调用中返回的所有内容?以及我如何知道返回的每件商品的含义?

【问题讨论】:

  • 返回什么数据完全取决于第三方。他们可能没有针对所有位置的全套数据。您最好向数据提供者自己索取信息。
  • 罗里是对的。他们的 api 有时不返回 rain.3h 数据,有时它为 0,我也遇到了同样的问题。也许是时候检查另一个 api,如 forecast.io

标签: javascript jquery jquery-plugins weather weather-api


【解决方案1】:

如果你看一下这个页面,你会发现一些返回的键实际上是可选的:

http://openweathermap.org/wiki/API/2.0/Weather_Data

即使是显而易见的weather 键也是可选的! :)

【讨论】:

  • 谢谢。是否有 2.5 版的 wiki?这个 API 的文档不是很清楚。
  • @BrendanVogt 天气数据自 2.0 版以来没有改变 :)
  • @BrendanVogt- 以下是 API 2.5 中使用的参数摘要- openweathermap.org/weather-data#current
猜你喜欢
  • 2018-09-11
  • 1970-01-01
  • 2015-02-22
  • 2021-12-23
  • 1970-01-01
  • 1970-01-01
  • 2020-09-09
  • 2019-05-28
  • 1970-01-01
相关资源
最近更新 更多