![](/img/trans.png)
[英]Display string of Json deserialized variable in label in usercontrol
[英]How to display an icon from a json string in a Label
我有: api并想在数组天气中显示图标 - >图标。
现在我只在 iOS 的显示屏上显示此 API 中的字符串,但我看不到图标图像。
我的MainPage.xaml
看起来像这样:
<Frame CornerRadius="10"
OutlineColor="Red"
Margin="10,0,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”翻译成 url。 见https://www.weatherbit.io/api/codes
<Image Source="https://www.weatherbit.io/static/img/icons/r01n.png" />
您可以像这样构建 url
var url = $"https://www.weatherbit.io/static/img/icons/{weatherData.weatherForecast[0].Weather.Icon}.png";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.