Get data via JSON by URL in C #

3

I need to get data via JSON, through a URL, this link: link

I'm trying with the code below, but I already get error as soon as it downloads the string.

The error you received is:

  

The character string is not in JSON format.

However, by the (little) I understand, it seems that the return is OK in the format.

Any idea what might be happening?

This is my code:

using (var webClient = new System.Net.WebClient())
        {
            var json = webClient.DownloadString("https://cryptohub.online/api/market/ticker/EGX/");

            dynamic obj = JsonConvert.DeserializeObject(json);

            var btc = 0.0;


                foreach (var result in obj.BTC_EGX)

                btc = result.last;
    
asked by anonymous 12.06.2018 / 04:51

1 answer

3

Hello! there was an update on the TLS protocol for 1.2 with that https calls stopped working because they were set to the old TLS 1.0. Arrow the Secutiry Protocol of System.Net as I added in your example below. abs

using (WebClient webClient = new System.Net.WebClient())
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            var json = webClient.DownloadString("https://cryptohub.online/api/market/ticker/EGX/");

            dynamic obj = JsonConvert.DeserializeObject(json);

            var btc = 0.0;


            foreach (var result in obj.BTC_EGX)

                btc = result.last;

        }
    
12.06.2018 / 05:32