1

I am learning C# and want to use the Riot API. I just want to receive that:

    {  
   "type":"champion",
   "version":"6.1.1",
   "data":{  
      "Thresh":{  
         "id":412,
         "key":"Thresh",
         "name":"Thresh",
         "title":"the Chain Warden"
      },
      "Aatrox":{  
         "id":266,
         "key":"Aatrox",
         "name":"Aatrox",
         "title":"the Darkin Blade"
      },...

I found this here: Deserialize JSON from Riot API C#

Can someone help me? I have no Idea what to do.

sincerly MasterR8

PS: I already googled 3 hours...

Community
  • 1
  • 1
Sidereus
  • 200
  • 3
  • 13
  • I tried to open a stream and wait for a respond. But I had no Idea what I was doing... I guess the problem is, that i dont know what Keywords i have to google to find the solution. – Sidereus Feb 19 '16 at 14:24

1 Answers1

1

If you want to get the json string try this, this take a URL and tries to do the request and returns the response. You can find the url in the sandbox mode provided on the riot API site.

using System.Net;
using System.IO;
public string GET(string url)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

        try
        {
            WebResponse response = request.GetResponse();
            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                return reader.ReadToEnd();
            }
        }
        catch (WebException ex)
        {
            WebResponse errorResponse = ex.Response;
            using (Stream responseStream = errorResponse.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
                String errorText = reader.ReadToEnd();
            }
            throw;
        }
    }

This is the easy part :) mapping the response to a POCO is what annoys me the most. If anybody reads this and has a good solution plzz link me.

Lode Vlaeminck
  • 894
  • 1
  • 9
  • 24
  • Youre the best! I could receive informations:) thanks for your Help. – Sidereus Feb 19 '16 at 15:11
  • You might want to change the error handeling, got this code from an old project, and i did something that was specific for the Api. But Why invent hot water, a quick look around on github and i found this project: https://github.com/sdesyllas/RiotApi.NET – Lode Vlaeminck Feb 19 '16 at 15:14