繁体   English   中英

如何从 Yahoo API JSON 获取天气图标?

[英]How can I get weather icon from Yahoo API JSON?

我在 Yahoo 的 JavaScript 中使用了天气 API,但是响应中没有对象给我天气图标,下面的代码显示了 JSON 响应。 如何从 API 获取图标天气?

——

current_observation:

astronomy: {sunrise: "6:06 am", sunset: "7:11 pm"}

atmosphere: {humidity: 53, visibility: 10, pressure: 26.96, rising: 0}

condition: {text: "Clear", code: 31, temperature: 71}

pubDate: 1566507600

wind: {chill: 71, direction: 338, speed: 3.73}

__proto__: Object

forecasts: Array(10)
0: {day: "Fri", date: 1566507600, low: 66, high: 95, text: "Sunny", …}
1: {day: "Sat", date: 1566594000, low: 67, high: 92, text: "Sunny", …}
2: {day: "Sun", date: 1566680400, low: 67, high: 91, text: "Sunny", …}
3: {day: "Mon", date: 1566766800, low: 66, high: 91, text: "Sunny", …}
4: {day: "Tue", date: 1566853200, low: 65, high: 91, text: "Sunny", …}
5: {day: "Wed", date: 1566939600, low: 66, high: 91, text: "Sunny", …}
6: {day: "Thu", date: 1567026000, low: 68, high: 90, text: "Sunny", …}
7: {day: "Fri", date: 1567112400, low: 68, high: 90, text: "Sunny", …}
8: {day: "Sat", date: 1567198800, low: 68, high: 91, text: "Sunny", …}
9: {day: "Sun", date: 1567285200, low: 68, high: 90, text: "Sunny", …}

length: 10
__proto__: Array(0)

location:
city: "Amman"
country: "Jordan"
lat: 31.951771
long: 35.940449
region: " Amman"
timezone_id: "Asia/Amman"
woeid: 1968902

根据https://developer.yahoo.com/weather/documentation.html#json-example 上的 Yahoo API,您没有。

您应该根据forecaststext值使用自己的图标。

前任:

{
    "forecasts":[
       {
          "day":"Tue",
          "date":1546934400,
          "low":52,
          "high":61,
          "text":"Rain",  // Take this value, and use your own image based on it.
          "code":12
       }
    ]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM