-3

I see that my APIController is returning a JSON but formatted as text, which means I have to parse it in client in order to manipulated it, and I want to avoid that.

I tried several things that are mentioned in this site and none worked.

What can I do?

Here is the controller method:

public async Task<IActionResult> Get()
{
    var ordersList =  await _ordenExternaService.GetOrdenExternaCasos();

    var json = JsonConvert.SerializeObject(casos);

    return Ok(json);
}

Here is the Postman result:

"[{\"Id\":3,\"IdOrdenExterna\":9041,\"NroCaso\":null,\"Motivo\":\"Nombre y Apellido de envio Completo no coincide con el del titular de la Tarjeta\",\"FechaEnvio\":null,\"NroOrdenPublica\":\"187901-205292-1665\"}]"
1
  • 4
    it's because you are serilizing it twice.... Commented Aug 25, 2021 at 12:04

1 Answer 1

3

That's because you are double encoding the return value. Your action should really be

public async Task<IActionResult> Get()
{
   var ordersList = await _ordenExternaService.GetOrdenExternaCasos();

   return Ok(ordersList);
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! it worked.
In that case, please accept the answer too.
I will, I have to wait 5 minutes to do that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.