For some reason, I can't get my data to feed my existing XAML list.
XAML
<ListView x:Name="DList"
ItemsSource="{Binding Items}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10">
<Image x:Name="img" Source="{Binding Image}" Aspect="AspectFill" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
MODEL 1
public class Model
{
public List<ImageUrl> Image { get; set; }
}
public class ImageUrl
{
public string Image { get; set; }
}
Model2 (This is the model I get if I convert the JSON data to c#)
public class Image
{
public string href { get; set; }
public object links { get; set; }
public object linkTemplates { get; set; }
}
public class Breed
{
public Image image { get; set; }
public object links { get; set; }
public object linkTemplates { get; set; }
}
public class RootObject
{
public List<Breed> breeds { get; set; }
public object links { get; set; }
public object linkTemplates { get; set; }
}
GETDATA
if (result.IsSuccessStatusCode)
{
var data = await result.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<List<Model>>(data);
}
data is correct, I received what I need. however, is on var response that it breaks.
If your code breaks in on JsonConvert.DeserializeObject
, you haven't properly created the class according to your json string, or it may not desirialize to List<Model>
at all. My guess would be that you need to have some class that has a List<Model>
field and use it to desirialize the json, that is the most common error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.