コード例 #1
0
        public static List<Spells> GetSpells(string region, string apiKey)
        {
            List<Spells> SpellsCollection = new List<Spells>();
            WebClient Client = new WebClient();
            Stream Data = Client.OpenRead("https://global.api.pvp.net/api/lol/static-data/eune/v1.2/summoner-spell?api_key=" + apiKey);
            StreamReader Reader = new StreamReader(Data);
            string Result = Reader.ReadLine();
            Result = Result.Replace("{", string.Empty);
            Result = Result.Replace("}", "|");
            Result = Result.Replace("\"", string.Empty);
            Result = Result.Replace(":", "|");
            Result = Result.Replace("id", string.Empty);
            Result = Result.Replace("description", string.Empty);
            Result = Result.Replace("name", string.Empty);
            Result = Result.Replace("key", string.Empty);
            Result = Result.Replace("summonerLevel", string.Empty);
            Result = Result.Replace(",|", "|");
            Result = Result.Replace("Turret|", "Turret:");
            Result = Result.Replace("|||", string.Empty);
            Result = Result.Replace("||", "|");
            Result = Result.Remove(0, Result.IndexOf("data") + 5);
            string[] words = Result.Split('|');

            Spells [] spell = new Spells[128];
            int y = 0;
            int x = 0;
            int z = 0;
            foreach (string word in words)
            {
                if(y == 1)
                {
                    spell[z] = new Spells();
                }
                switch (y)
                {
                    case 0:
                        break;
                    case 1:
                        spell[z].Name = words[x];
                        break;
                    case 2:
                        spell[z].Description = words[x];
                        break;
                    case 3:
                        spell[z].SummonerLevel = int.Parse(words[x]);
                        break;
                    case 4:
                        spell[z].Id = int.Parse(words[x]);
                        break;
                    case 5:
                        spell[z].Key = words[x];
                        break;
                }
                if (y == 5)
                {
                    y = -1;
                    SpellsCollection.Add(spell[z]);
                    z++;
                }
                y++;
                x++;
            }
            return SpellsCollection;
        }