I want to retrieve a collection of football leagues from an external api. The response from the server comes as shown below:
{
"api": {
"results": 1496,
"leagues": [
{
"league_id": 1,
.....
The returned object constists of an "api" field which hold "results" and "leagues". I would like deserialize the code and map it to League class objects in my code.
var jsonString = await ExecuteUrlAsync(filePath, url);
var results = JsonConvert.DeserializeObject<IEnumerable<LeagueEntity>>(jsonString);
jsonString is correct, but when the program hits second line I get an exception:
Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.IEnumerable".
I need to get to the "leagues" field in JSON file, and ignore the rest of the response. How to achieve that?