0
Hello, I have a very simple test. A method returns a JSON(), but how I access the values within this return?
In the Test method I would like to use some value of the returned JSON. Could you help? Thank you.
namespace DGBar.Controllers {
public class TestController : ApiController {
[HttpGet]
public IHttpActionResult Index() {
return Json(new { Nome = "Rafael", Idade = 34 });
}
[Route("teste")]
[HttpGet]
public IHttpActionResult Teste() {
var result = Index();
return Json(JsonConvert.DeserializeObject(result).Nome);
}
}
}
I don’t think it’s gonna work that way... the method
Index()
will return an Htttpactionresult and not the object you are trying to deserialize... you would have to make a request in the methodTeste()
or prepare it to receive Json as parameter/argument.– Leandro Angelo
Thank you for the strength. I really needed to make some Sts to succeed. Here’s how I did it.
– osmarditto