JavaEar 专注于收集分享传播有价值的技术资料

C# Cannot access child value on Newtonsoft.Json.Linq.JValue

How would i access the "leaguePoints"?

    using (var http = new HttpClient())
    {
        var result = JObject.Parse(await http.GetStringAsync($"https://euw.api.riotgames.com/api/lol/EUW/v2.5/league/by-summoner/12345678/entry?api_key=" + apikey).ConfigureAwait(false));
        var something = (Uri.EscapeUriString(result["12345678"][0]["tier"]["leaguePoints"].ToString()));
    }

I also tried adding an [0] after ["tier"], but in both scenarios it gives me the error

Cannot access child value on Newtonsoft.Json.Linq.JValue.

Json example response below:

{
    "12345678": [
        {
            "tier": "PLATINUM",
            "queue": "RANKED_SOLO_5x5",
            "name": "Taric's Templars",
            "entries": [
                {
                    "isFreshBlood": false,
                    "division": "III",
                    "isVeteran": false,
                    "wins": 9,
                    "losses": 1,
                    "playerOrTeamId": "12345678",
                    "playerOrTeamName": "noname123",
                    "isInactive": false,
                    "isHotStreak": false,
                    "leaguePoints": 0
                }
            ]
        }
    ]
}

1个回答

    最佳答案
  1. "leaguePoints" seems to be in "entries" rather than in "tier":

     result["12345678"][0]["entries"][0]["leaguePoints"]