I have a problem that I can not solve, I hope you help me.
In my Xamarin.Forms application I am downloading JSON data which I would like to display in ListView.
JSON nasted data looks like this:
{
"devices": [
{
"id": 2,
"name": "device1",
"owner": {
"owner_id": 10,
"owner_surname": "XYZ"
}
},
{
"id": 3,
"name": "device3",
"owner": {
"owner_id": 12,
"owner_surname": "XVB"
}
}
]
}
I have such classes for these data:
public class Items
{
public List<Device> devices { get; set; }
}
public class Device
{
public int id { get; set; }
public string name { get; set; }
public Owner owner { get; set; }
}
public class Owner
{
public int owner_id { get; set; }
public string owner_surname { get; set; }
}
This is my MainPage.xaml.cs file:
var client = new WebClient();
client2.Headers.Add("Accept", "application/json");
var content = client.DownloadString(Url);
var tr = JsonConvert.DeserializeObject<List<Items>>(content);
ObservableCollection<Items> trends = new ObservableCollection<Items>(tr);
myList.ItemsSource = trends;
And this is my ListView in XAML:
<ListView x:Name="myList" HasUnevenRows="true" ItemsSource="{Binding devices}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding name}" TextColor="Black" FontAttributes="Bold"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
This code does not display anything (white screen). I would like to display the "name" from the first level of nesting and the "owner_surname" from the second level of nesting. application built on the basis of: https://www.codementor.io/lutaayahuzaifahidris/xamarin-forms-simple-list-of-items-with-offline-capability-cross-platform-app-btyq0bihv Other responses to stackoverflow did not work :(
