コード例 #1
0
        private static List <Champion> GetChampions()
        {
            var pathBuilder  = new UrlPathBuilder();
            var championList = new List <Champion>();

            using (var client = new WebClient())
            {
                try
                {
                    var championsJson = client.DownloadString(pathBuilder.GetChampionsUrl());
                    var jsonObject    = JObject.Parse(championsJson);
                    foreach (JProperty champion in jsonObject["data"])
                    {
                        var championProperties = champion.Value;
                        var championName       = championProperties["name"].ToString();
                        championList.Add(new Champion
                        {
                            Name = championProperties["name"].Value <string>(),
                            Key  = championProperties["key"].Value <string>(),
                            Id   = championProperties["id"].Value <string>()
                        });
                    }

                    return(championList);
                }
                catch (Exception) { return(new List <Champion>()); }
            }
        }