如何解决如何从标签中的 json 字符串显示图标
我有:api 并且想在数组 weather -> Icon 中显示图标。
目前我只在 iOS 的显示屏上显示此 API 中的字符串,但我看不到图标图像。
我的 MainPage.xaml
看起来像这样:
<Frame CornerRadius="10"
OutlineColor="Red"
Margin="10,10,0"
BackgroundColor="White"
Opacity="0.5">
<StackLayout VerticalOptions="Center">
<Label x:Name="infoLabel"
Grid.ColumnSpan="3"
TextColor="Black"
HorizontalOptions="Center"
FontAttributes="Bold"
FontSize="15" />
<Label x:Name="infoLabel1"
Grid.ColumnSpan="3"
TextColor="Black"
HorizontalOptions="Center"
FontAttributes="Bold"
FontSize="15" />
</StackLayout>
</Frame>
我的 MainPage.xaml.cs
看起来像这样:
string Info = DateDays.DayOfWeek + DateDays.ToString(" MM/dd - HH:mm") + " " + weatherData.weatherForecast[0].Weather.Icon + " " + weatherData.weatherForecast[0].Temperature + "°C";
infoLabel.Text = Info;
string Info1 = DateDays1.DayOfWeek + DateDays1.ToString(" MM/dd - HH:mm") + " " + weatherData.weatherForecast[1].Weather.Icon + " " + weatherData.weatherForecast[1].Temperature + "°C";
infoLabel1.Text = Info1;
结果是:
显示图标的正确方式是什么?
解决方法
您必须将代码“r01n”翻译成网址。见https://www.weatherbit.io/api/codes
<Image Source="https://www.weatherbit.io/static/img/icons/r01n.png" />
你可以像这样构建网址
var url = $"https://www.weatherbit.io/static/img/icons/{weatherData.weatherForecast[0].Weather.Icon}.png";
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。