我正在为防暴游戏api开发一个api包装程序。我遇到以下端点问题:
champion-mastery / v4 / champion-masteries / by-summoner / {encryptedSummonerId}
我正在使用newtonsoft json和RestSharp来获取结果。这是我的代码。
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;
}
此模式已在大约80%的端点上起作用。但是,对于此特定端点,将返回JSON数组。像其他所有数组一样,这个特定的json数组也没有诸如“数据”或“条目”之类的键。所以我似乎无法弄清楚如何正确制作精通模型。这是我到目前为止所拥有的
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; }
}
适用于一个条目,但不适用于整个数组。添加列表似乎不起作用,因为没有密钥可作为列表的基础。
这里有一个JSON模式样本...
[
{
"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
}
]
感谢您的帮助。