I am getting the following from json payload from a REST request.
{
"version": "1.1",
"date": "2017-01-06",
"count": "130",
"0": {
"artist": "Artist 1",
"title": "Title 1"
},
"1": {
"artist": "Artist 2",
"title": "Title 2"
},
...
"49": {
"artist": "Artist 50",
"title": "Title 50"
}
}
As you can see, there are several numeric root elements. These elements index the object in the response, so I don't need the numbers themselves, I just need the Song
object they represent. I also need count
to know if I need to make a call to the server to get the next page of songs (the server returns 50 Song
objects max per call).
Here is what I have for Song
class:
public class Song
{
public string artist {get; set;}
public string title {get; set;}
}
But I am having issues getting the root element. I tried to mimic the process used when there is a dynamic child element, but this does not work.
public class SongsResponse
{
public string version { get; set; }
public string date { get; set; }
public string count {get; set; }
public Dictionary<string, Song> songs { get; set; }
}
I've seen solutions that "throw away" version
, date
and count
and others that do it without pre-defined classes.
But I need count
and ideally would want to work from predefined classes.