0
Good guys, I’m having a little problem consuming an API.
I am with an Aspnetmvc web application and need to consume an API.
First with a user selection I run this method below in the controller:
[HttpPost]
public JsonResult ChamadaTrade(String valor)
{
if (valor != null)
{
var saida = APICalling.Call();
return Json(saida);
}
else
{
var saida = "falha";
return Json(saida);
}
}
The intereface for the implementation of the call:
public interface IApiService
{
[Get("")]
Task<Data> GetDataAssync();
}
And the method that implements it:
[HttpGet("")]
public static async Task<string> Call()
{
try
{
IApiService ExchangeClient = RestService.For<IApiService>("https://api.coinlore.net/api/tickers/");
var dataExchange = await ExchangeClient.GetDataAssync();
return dataExchange.Name.ToString();
}
catch (Exception e)
{
return $"Erro na consulta dos dados " + e.Message;
}
}
Yet I’m getting Jsonexception "jsonexception a possible Object Cycle was Detected which is not supported"
I just wanted to know if my code has some wrong implementation or if I need to do some JSON conversion that I’m not doing.
Hello, it’s a JSON setup. Your object is probably circular referenced Ex.: class Parent { public List<Child> children {get;set; } and class Child { public Parent {get;set; }; When the program will transform the object into JSON string, it will loop between the references of the two objects. You will need to ignore the error in the object serialize to avoid this type of circular reference.
– Anderson Koester