Hello, I'm having trouble deserializing a node from a JSON object to a list. The object I have is the following:
{
"paging": {"total":67, "page":1, "offset":0, "limit":30, "maxLimit":50 },
"sort": [ {"id":"asc"} ],
"availableFilters": [ "status", "type" ],
"appliedFilters": [],
"OrderStatuses":[
{
"OrderStatus":{
"id":"1",
"status":"A ENVIAR",
"type":"open",
"show_backoffice":"1"
}
},
...
]
}
I need to deserialize the elements that are within OrderStatuses
to a list of class OrderStatus
that is below:
public class OrderStatus {
public int id { get; set; }
public string status { get; set; }
public string type { get; set; }
public int show_backoffice { get; set; }
}
My problem is that, I can not simply construct a class containing OrderStatuses
as a class property and within it a OrderStatus
list because that response varies between API's URLs and that name "OrderStatuses" changes to each route. My intention is to create a generic class where I can, based on some parameter already bring the correct list as well.
public class Response<T> {
public Response(string listName) => ListName = listName;
public ListName { get; set; }
public List<T> deserializeList(string json) {
var array = JObject.Parse(json).SelectToken(ListName);
// não sei como transformar o JEnumerable para uma List<T>
}
}
Could anyone help me?