Currently I am using C# like so to access a particular endpoint from a sports statistics API
class GetPlayerData
{
public string retrievePlayerStats()
{
var URL = new UriBuilder("https://statsapi.web.nhl.com/api/v1/people/8471698/stats?stats=statsSingleSeason&season=20202021");
var client = new WebClient();
dynamic PlayerData = JObject.Parse(client.DownloadString(URL.ToString()));
string PlayerStats = PlayerData.stats.ToString();
return PlayerStats;
}
}
The call works with no issue returning the following result seen formatted at the link below:
https://statsapi.web.nhl.com/api/v1/people/8471698/stats?stats=statsSingleSeason&season=20202021
My question is how do I access the items in the sub-array "splits". I want to be able to bring back a single stat for the player like goals or time on ice. If I try the commented options below I receive an error that says "Cannot perform runtime binding on a null reference". I am fairly new to C# so hopefully the answer is easy and any help (or even other options completely) on how to do this is much appreciated.
public string retrievePlayerStats()
{
var URL = new UriBuilder("https://statsapi.web.nhl.com/api/v1/people/8471698/stats?stats=statsSingleSeason&season=20202021");
var client = new WebClient();
dynamic PlayerData = JObject.Parse(client.DownloadString(URL.ToString()));
string PlayerName = PlayerData.stats.ToString();
//string PlayerName = PlayerData.splits.ToString(); --null reference error
//string PlayerName = PlayerData.stats.splits.ToString(); --null reference error
return PlayerName;
}
Thank you!