1

暴動ゲーム API の API ラッパーに取り組んでいます。次のエンドポイントで問題が発生しています。

チャンピオンマスタリー/v4/チャンピオンマスタリー/バイサモナー/{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; }
}

これは 1 つのエントリでは機能しますが、配列全体では機能しません。リストのベースとなるキーがないため、リストの追加は機能しないようです。

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
    }
]

どんな助けでも大歓迎です、ありがとう。

4

0 に答える 0