Filme.cs
using System.Text.Json.Serialization;
namespace Cinema.Modelos;
class Filme {
[JsonPropertyName("rank")]
public string? Rank {get;set;}
[JsonPropertyName("title")]
public string? NomeAbreviado {get;set;}
[JsonPropertyName("FullTitle")]
public string? NomeCompleto {get;set;}
[JsonPropertyName("year")]
public string? AnoLancamento {get;set;}
[JsonPropertyName("image")]
public string? Imagem {get;set;}
[JsonPropertyName("crew")]
public string? GrupoAtores {get;set;}
public void ExibirDetalhes() {
Console.WriteLine();
Console.WriteLine($"Rank: {Rank}");
Console.WriteLine($"Nome: {NomeAbreviado}");
Console.WriteLine($"Nome Completo: {NomeCompleto}");
Console.WriteLine($"Ano de lançamento: {AnoLancamento}");
Console.WriteLine($"Link imagem: {Imagem}");
Console.WriteLine($"Participantes: {GrupoAtores}");
Console.WriteLine();
}
}
Program.cs
using System.Text.Json;
using Cinema.Modelos;
Console.Clear();
using (HttpClient client = new()) {
try {
var response = await client.GetStringAsync("https://raw.githubusercontent.com/ArthurOcFernandes/Exerc-cios-C-/curso-4-aula-2/Jsons/TopMovies.json");
var listaFilmes = JsonSerializer.Deserialize<List<Filme>>(response);
listaFilmes!.ForEach(f => f.ExibirDetalhes());
}
catch (Exception ex) {
Console.WriteLine($"Um erro foi encontrado na requisição: {ex}");
}
}