Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

json

c#

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
                }
            ]
        }
    ]
}
like image 796
datboi Avatar asked Dec 17 '25 21:12

datboi


1 Answers

"leaguePoints" seems to be in "entries" rather than in "tier":

 result["12345678"][0]["entries"][0]["leaguePoints"]
like image 51
Ain Avatar answered Dec 20 '25 12:12

Ain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!