如何从 Ionic 3

问题描述

我正在尝试使用 Ionic 3 和 weather.org API 从 JSON 对象中检索图标。 JSON 结构如下:

enter image description here

JSON 对象按预期重新调整,所有其他字段均可访问。当我尝试引用该图标时,我收到“找不到资源”的消息: 这是我的 HTML 文件中的调用,其中 weatherToday 是 JSON 对象:

{{weatherToday?.weather[0]?.icon}}

进行其他 API 调用时,图像由 url 表示:

enter image description here

哪些是可检索的:

this.weatherImage = this.weatherToday.weather[0].main;

那么我的问题是如何检索第一个 JOSN 对象中 Icon 键的 Icon 值?

解决方法

可能对使用 openweathermap.org API 的其他人有所帮助,在进一步查看 documentation 后,有一个对前面 URL 的引用,该 URL 需要添加到从 JSON 对象返回的 Icon 键的值之前:http://openweathermap.org/img/wn/{Icon_Value}.png