I am working on an api wrapper for the riot games api. I am running into an issue with the following endpoint:
champion-mastery/v4/champion-masteries/by-summoner/{encryptedSummonerId}
I am using newtonsoft json and RestSharp to get the results. Here is my code.
public Masteries getMasteriesBySummoner(string id, string server)
{
RestClient client = new RestClient($"https://{getServer(server)}.api.riotgames.com/lol/");
RestRequest request = new RestRequest($"champion-mastery/v4/champion-masteries/by-summoner/{id}");
request.AddHeader("X-Riot-Token", key);
var response = client.Get(request);
Masteries masteries = JsonConvert.DeserializeObject<Masteries>(response.Content);
return masteries;
}
This pattern has worked for about 80% of the endpoints. However for this particular endpoint a JSON array is returned. This particular json array also has no key such as 'data' or 'entries' like all the other ones do. So I cant seem to figure out how to make the masteries model correctly. Here is what I have so far
public class Masteries
{
public int championLevel { get; set; }
public bool chestGranted { get; set; }
public int championPoints { get; set; }
public int championPointsSinceLastLevel { get; set; }
public int championPointsUntilNextLevel { get; set; }
public string summonerId { get; set; }
public int tokensEarned { get; set; }
public int championId { get; set; }
public object lastPlayTime { get; set; }
}
which works for one entry, but not for the whole array. Adding a list doesnt seem to work as there is no key to base the list on.
Heres a sample of the JSON Pattern...
[
{
"championLevel": 7,
"chestGranted": false,
"championPoints": 70594,
"championPointsSinceLastLevel": 48994,
"championPointsUntilNextLevel": 0,
"summonerId": "xaZh_7U2VIRtArKG-mgda_Rt9TSRVRmhBp2GFE88bmTSqJU",
"tokensEarned": 0,
"championId": 10,
"lastPlayTime": 1537676432000
},
{
"championLevel": 7,
"chestGranted": true,
"championPoints": 51273,
"championPointsSinceLastLevel": 29673,
"championPointsUntilNextLevel": 0,
"summonerId": "xaZh_7U2VIRtArKG-mgda_Rt9TSRVRmhBp2GFE88bmTSqJU",
"tokensEarned": 0,
"championId": 69,
"lastPlayTime": 1548208513000
}
]
Any help is appreciated, thanks.