public class Filme
{
[JsonPropertyName("id")]
public string Codigo { get; set; }
[JsonPropertyName("rank")]
public string Ranque { get; set; }
[JsonPropertyName("title")]
public string Titulo { get; set; }
[JsonPropertyName("fullTitle")]
public string TituloCompleto { get; set; }
[JsonPropertyName("year")]
public string Ano { get; set; }
[JsonPropertyName("image")]
public string Imagem { get; set; }
[JsonPropertyName("crew")]
public string Elenco { get; set; }
[JsonPropertyName("imDbRating")]
public string ClassificacaoImdDb { get; set; }
[JsonPropertyName("imDbRatingCount")]
public string ClassificacaoImdDbTotal { get; set; }
public string FichaTecnica => $"\n\nTitulo: {Titulo} ({Ano}) - Nota: {ClassificacaoImdDb}\nElenco: [{Elenco}]\n\n";
}
public class Pais
{
[JsonPropertyName("nome")]
public string Nome { get; set; }
[JsonPropertyName("capital")]
public string Capital { get; set; }
[JsonPropertyName("populacao")]
public int Populacao { get; set; }
[JsonPropertyName("continente")]
public string Continente { get; set; }
[JsonPropertyName("idioma")]
public string Idioma { get; set; }
public string Informacoes => $"Pais: {Nome} - Capital: {Capital} - Populacao: {Populacao}";
}
public class Carro
{
[JsonPropertyName("arca")]
public string Marca { get; set; }
[JsonPropertyName("modelo")]
public string Modelo { get; set; }
[JsonPropertyName("ano")]
public int Ano { get; set; }
[JsonPropertyName("tipo")]
public string Tipo { get; set; }
[JsonPropertyName("motor")]
public string Motor { get; set; }
[JsonPropertyName("transmissao")]
public string Transmissao { get; set; }
public string Informacoes => $"Carro {Marca} {Modelo} {Ano} {Tipo}";
}
public class Livro
{
[JsonPropertyName("titulo")]
public string Titulo { get; set; }
[JsonPropertyName("autor")]
public string Autor { get; set; }
[JsonPropertyName("ano_publicacao")]
public int AnoPublicacao { get; set; }
[JsonPropertyName("genero")]
public string Genero { get; set; }
[JsonPropertyName("paginas")]
public int Paginas { get; set; }
[JsonPropertyName("editora")]
public string Editora { get; set; }
public string FichaTecnica => $"Titulo: {Titulo}\nAutor: {Autor}\nAno: {AnoPublicacao}\nGenero: {Genero}\n\n";
}
using (HttpClient client = new HttpClient())
{
try
{
string resposta = await client.GetStringAsync("https://raw.githubusercontent.com/ArthurOcFernandes/Exerc-cios-C-/curso-4-aula-2/Jsons/TopMovies.json");
var filmes = JsonSerializer.Deserialize<List<Filme>>(resposta)!;
foreach(var filme in filmes)
{
Console.WriteLine(filme.FichaTecnica);
}
}
catch (System.Exception ex)
{
Console.WriteLine($"Temos um problema: {ex.Message}");
}
}
using (HttpClient client = new HttpClient())
{
try
{
string resposta = await client.GetStringAsync("https://raw.githubusercontent.com/ArthurOcFernandes/Exerc-cios-C-/curso-4-aula-2/Jsons/Paises.json");
var paises = JsonSerializer.Deserialize<List<Pais>>(resposta)!;
foreach(var pais in paises)
{
Console.WriteLine(pais.Informacoes);
}
}
catch (System.Exception ex)
{
Console.WriteLine($"Temos um problema: {ex.Message}");
}
}
using (HttpClient client = new HttpClient())
{
try
{
string resposta = await client.GetStringAsync("https://raw.githubusercontent.com/ArthurOcFernandes/Exerc-cios-C-/curso-4-aula-2/Jsons/Carros.json");
var carros = JsonSerializer.Deserialize<List<AtividadeFilmes.Carro>>(resposta)!;
foreach(var carro in carros)
{
Console.WriteLine(carro.Informacoes);
}
}
catch (System.Exception ex)
{
Console.WriteLine($"Temos um problema: {ex.Message}");
}
}
using (HttpClient client = new HttpClient())
{
try
{
string resposta = await client.GetStringAsync("https://raw.githubusercontent.com/ArthurOcFernandes/Exerc-cios-C-/curso-4-aula-2/Jsons/Livros.json");
var livros = JsonSerializer.Deserialize<List<Livro>>(resposta)!;
foreach(var livro in livros)
{
Console.WriteLine(livro.FichaTecnica);
}
}
catch (System.Exception ex)
{
Console.WriteLine($"Temos um problema: {ex.Message}");
}
}