C#无法访问Newtonsoft.Json.Linq.JValue上的子值

时间:2017-04-01 20:04:36

标签: c# json

我如何访问“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()));
    }

我还尝试在[0]之后添加["tier"],但在这两种情况下都会给我错误

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

以下Json示例回复:

{
    "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 个答案:

答案 0 :(得分:3)

“leaguePoints”似乎是在“条目”而不是“等级”中:

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