Classe Movie:
using System.Text.Json.Serialization;
namespace exercise93.Models;
internal class Movie
{
[JsonPropertyName("id")]
public string? Id { get; set; }
[JsonPropertyName("rank")]
public string? Rank { get; set; }
[JsonPropertyName("fullTitle")]
public string? Title { get; set; }
[JsonPropertyName("imDbRating")]
public string? Rating { get; set; }
public string DetailedDescription => $"Title {Title} - Rank {Rank} - Rating {Rating}";
}
Program:
using exercise93.Models;
using System.Text.Json;
using (HttpClient client = new HttpClient())
{
try
{
string response = await client.GetStringAsync("https://raw.githubusercontent.com/ArthurOcFernandes/Exerc-cios-C-/curso-4-aula-2/Jsons/TopMovies.json");
List<Movie> movies = JsonSerializer.Deserialize<List<Movie>>(response)!;
foreach(Movie movie in movies)
{
Console.WriteLine(movie.DetailedDescription);
}
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
}
}