I am trying to convert json that I deserialized to a class to a datatable by using the code below ,however the code below fails at the last line.
using (var webClient = new System.Net.WebClient())
{
var downloadTable = webClient.DownloadString(url);
var myTable = JsonConvert.DeserializeObject<leagueTable>(downloadTable);
DataTable dt = myTable;
}
I know that I could deserialized directly to a datatable but I want to deserialized it to a class first so that I can manipulate the data and let the structure of the data be known to others that use the code.
The JSON is nested and the classes made for it is below
public class leagueTable
{
public string leaguename { get; set; }
public int gameday { get; set; }
public System.Collections.ObjectModel.Collection<Ranking> ranking { get; set; }
}
public class Ranking
{
public int rank { get; set; }
public string club { get; set; }
public int games { get; set; }
public int points { get; set; }
}