1
Good afternoon, I am making a web application for college where I need to consume a C#Climatempo API, in my code, I am passing as parameter the code of the city and making the request for the: https://advisor.climatempo.com.br
This is my request URL at the end: http://apiadvisor.climatempo.com.br/api/v1/weather/locale/3480/current?token=866474fc3c51b2f4229db9d8f11648de
So far so good, I created the fields in VIEW to inform the city code and Controller to search:
public ActionResult PrevisaoTempo(UsuarioCliente usuario)
{
string url = "http://apiadvisor.climatempo.com.br/api/v1/weather/locale/"+usuario.Cod+"/current?token=866474fc3c51b2f4229db9d8f11648de";
WebClient client = new WebClient();
string json = client.DownloadString(url);
byte[] bytes = Encoding.Default.GetBytes(json);
json = Encoding.UTF8.GetString(bytes);
usuario = JsonConvert.DeserializeObject<UsuarioCliente>(json);
TempData["Usuario"] = usuario;
return RedirectToAction("Create", "PrevisaoTempo");
}
The point is, it brings JSON all right and I can even show in the view the information behind JSON’s "DATA". But after DATA, it becomes NULL after going through the Deserializeobject and so the temperature and Sensation fields arrive null’s in the VIEW, can you help me with that? Thank you very much!
In case I just want to bring the temperature and Sensation of the DATA vector User class:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace ProjetoCotacao2.Models
{
[Table("UsuarioClientes")]
public class UsuarioCliente
{
[Key]
public int IDUsuarioCliente { get; set; }
[Display(Name = "E-mail")]
[EmailAddress(ErrorMessage = "E-mail inválido!")]
public string Email_Cliente { get; set; }
[Required(ErrorMessage = "Campo obrigatório!")]
[Display(Name = "Login do usuário")]
public string Login { get; set; }
[Display(Name = "Senha")]
[DataType(DataType.Password)]
[Required(ErrorMessage = "Campo obrigatório!")]
public string SenhaCliente { get; set; }
[Display(Name = "Confirmação Senha")]
[Compare("SenhaCliente", ErrorMessage = "Os campos não coincidem!")]
[DataType(DataType.Password)]
[NotMapped]
public string ConfirmacaoSenha { get; set; }
[Display(Name = "CPF")]
[Required(ErrorMessage = "Campo obrigatório!")]
public string CPF_Cliente { get; set; }
[Display(Name = "Nome")]
[MinLength(3, ErrorMessage = " No mínimo 3 caracteres")]
[Required(ErrorMessage = "Campo obrigatório!")]
public string Nome_Cliente { get; set; }
[Display(Name = "Telefone")]
[Required(ErrorMessage = "Campo obrigatório!")]
public string Telefone_Cliente { get; set; }
public string Cep { get; set; }
public string Logradouro { get; set; }
public string Localidade { get; set; }
public string Name { get; set; }
public string Id { get; set; }
public string State { get; set; }
public string temperature { get; set; }
public string sensation { get; set; }
}
}
Poste a class Usuariocliente
– Netinho Santos
I updated the post
– Airton Dambrovski
your class is quite different from what json returns
– Ricardo Pontual
The class belongs to a larger project, the Climate API is part of the project
– Airton Dambrovski