不知道如何让天气图标出现

问题描述 投票:0回答:1

我正在开发一个天气应用程序,一旦您输入一个新城市,该应用程序就会更新显示天气和代表天气的图标。但是,我从 API 下载了包含所有图标的 JSON 文件,但我不确定如何在应用程序中调用或更新它。以下是 Git 存储库的链接:(https://github.com/jscruggsce/Weather-App)

不确定如何引用 JSON 文件

javascript html json
1个回答
0
投票

在 api 中提供 i 图标,如下所示:

"current": {
    "last_updated_epoch": 1726509600,
    "last_updated": "2024-09-16 19:00",
    "temp_c": 19.8,
    "temp_f": 67.7,
    "is_day": 1,
    "condition": {
      "text": "Sunny",
      "icon": "//cdn.weatherapi.com/weather/64x64/day/113.png",
      "code": 1000
    },
    ...

您可以从 current.condition.icon 中获取它,在您的

checkWeather
函数中类似这样:

weatherIcon.src = data.current.condition.icon;
© www.soinside.com 2019 - 2024. All rights reserved.