Convert UTF-8 string to C#standard format

Asked

Viewed 121 times

1

I’m downloading a string via WebClient() and I get a string with the badly formed accents.

Example:

{"fíddiesticks":{"id":4078584,"name":"FíddIesticks","profileIconId":946,"summonerLevel":30,"revisionDate":1475092874000}}

I know that the string that I get is in UTF-8, but I am unable to convert to the standard format of C# I don’t even know what it is.

Code:

private void buttonSummonerBrowse_Click(object sender, EventArgs e)
{
    WebClient webClientSummonerInfo0 = new WebClient();
    webClientSummonerInfo0.DownloadStringCompleted += new DownloadStringCompletedEventHandler(SummonerInfo0_DownloadStringCompleted);
    webClientSummonerInfo0.DownloadStringAsync(new Uri("https://br.api.pvp.net/api/lol/" + comboBoxSummonerRegion.SelectedItem + "/v1.4/summoner/by-name/" + textBoxSummonerName.Text + "?api_key=" + __apiKey));

}

private void SummonerInfo0_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    MessageBox.Show(e.Result);
}
  • you set to receive in UTF-8? How is your code!

  • On the site, the information is in UTF-8, as soon as I get, I show her in a Messagebox.Show()

  • I made an answer see if it works!

1 answer

1

So set it up like this: (upon comment)

WebClient webClientSummonerInfo0 = new WebClient();
webClientSummonerInfo0.Encoding = Encoding.UTF8;

Webclient.Encoding Property

  • Perfect! I didn’t know that the Webclient() class had this, it came out exactly as expected. Thanks!

  • 1

    It does, Okay, @Icarus !!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.