From a C# program I am calling an RestFul API in an external system.
The calling finally is done with this code:
string response = await cliente.GetDataByPost($"/index.php?route=api/catalog/products&token={authentication.api_token}", null, null);
List<Models.Producto> productos = JsonConvert.DeserializeObject<List<Models.Productos>>(response);
response
variable coming from the external system is the json string shown in the following image:
Under 42, 30, 47, and so on, are the ordinary product
objects (the same number as the ID). That object has several properties, so for the case now, it is not important to post here. I can only say that the object is the Models.Producto
entity.
Of course, that DeserializeObject
call returns an error.
I call this json string a weird object because in order to deserialize using normal deserialization procedure, those numbers (42, 30, 47, etc.) should be properties of products
object.
How can I configure JsonConvert
so that I can deserialize this thing using the following entity models? Is this possible?
public class Productos
{
public Success success { get; set; }
}
public class Success
{
public List<Systems.Models.Producto> products { get; set; }
}
}