0
I have a little problem with deserializar
mine json
, and I don’t know why
public async Task<IActionResult> Index()
{
Uri BaseAdress = Services.Token.BaseAdress;
string strToken = Services.Token.strToken;
List<FormaPagamentoFinModel> ListaAmbientes;
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = BaseAdress;
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", strToken);
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("Application/Json"));
using (HttpResponseMessage response = await httpClient.GetAsync("/api/FormaPagamentoFin/findAll"))
{
response.EnsureSuccessStatusCode();
string resul = await response.Content.ReadAsStringAsync();
ListaAmbientes = JsonConvert.DeserializeObject<List<FormaPagamentoFinModel>>(resul);
}
}
return View(ListaAmbientes);
}
My variable resul
receives the normal data, but Deserializar
he returns to me everything null
, he returns me the count
correctly, but all variables with null value
Findall method in API:
[HttpGet]
[Route("findAll")]
public HttpResponseMessage findAll()
{
try
{
var result = new HttpResponseMessage(HttpStatusCode.OK);
var ambientes = bdprincipalEntities.forma_pagamento_fin.Select(
x => new {
Fpg_codigo = x.Fpf_codigo,
Fpg_descricao = x.Fpf_descricao,
Fpg_quantidade = x.Fpf_quantidade,
Fpg_situacao = x.Fpf_situacao.Equals("A") ? "ATIVO" : "DESATIVADO"
}).ToList();
result.Content = new StringContent(JsonConvert.SerializeObject(ambientes));
result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
return result;
}
catch (Exception)
{
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}
}
The model
FormaPagamentoFinModel
is the same returned by the method/api/FormaPagamentoFin/findAll
? How is this methodFindAll
?– Felippe Tadeu
I’ll ask the question, sorry
– Jeff Henrique
Wow, I’ve touched on the bug just now, I’m passing wrong on the api
– Jeff Henrique
Post an answer I accept
– Jeff Henrique