使用 xamarin c# iOS 在 .xaml 文件中显示 json 对象如何正确

问题描述

我有一个 API 可以在 .xaml 文件显示气象数据,如下所示:

      <Label Text="{Binding Coord.Lon}" 
                   Style="{StaticResource labelResultStyle}"
                   TextColor="White"
                   FontAttributes="Bold"
                   Grid.Row="2"
                   Grid.Column="0"
                   HorizontalOptions="CenterandExpand"/>

First API object

对于第二个 API,我尝试绑定数据:

<Label Text="{Binding weatherForecast.MaxTemp}" 
                       Style="{StaticResource labelResultStyle}"
                       FontAttributes="Bold"
                       HorizontalOptions="CenterandExpand"
                       HorizontalTextAlignment="Start"
                       TextColor="White"/>

显示器上没有结果。

我的第二个 Json 对象看起来像:

Second API object

我应该如何从 .xaml 文件中的第二个对象调用数据?

解决方法

weatherForecast 是一个对象的集合,因此您必须指定要使用集合的哪个元素

Text="{Binding weatherForecast[0].MaxTemp}"