1
namespace Monitorizacao.UI.Pages
{
public class Post {
public int Id { get; set; }
public string Title { get; set; }
public string Body { get; set; }
}
public partial class TestAPIPage : ContentPage
{
private const string url = "https://jsonplaceholder.typicode.com/posts";
private HttpClient _client = new HttpClient();
private ObservableCollection<Post> _posts;
public TestAPIPage()
{
InitializeComponent();
}
protected override async void OnAppearing()
{
var content = await _client.GetStringAsync(url);
var posts = JsonConvert.DeserializeObject<List<Post>>(content);
_posts = new ObservableCollection<Post>(posts);
List.ItemsSource = _posts;
Console.Write(posts);
base.OnAppearing();
}
}
}
I have a JSON and when I try to show it on a listview
after deserialize, the data does not show what I want.
When I do debug from the app, all data is received.
Henry, run a test and change the line
List.ItemsSource = _posts;
forList.ItemsSource = _posts.Select(p => p.Title).ToList();
– Jéf Bueno