1

I'm using Newtonsoft.Json package and after I deserialize some json object, I place the resulting string in a listBox. I noticed that if the text contains characters such as single quote, in my listbox the added text contains the value ’. I read that this is due to unicode or UTF8 encoding of the original string, but I don't know how to translate it so that my listBox will show the proper way.

I expect it is necessary to use a Decoding to UTF8 or Unicode?

    jsonData = JsonConvert.DeserializeObject(sJsonCode);
    foreach (var message in jsonData["messages"])                
    {
        string body = message.body.ToString();  // if message.body contains single quotes, they will be displayed as ’
        listBox1.Items.Add(body);
    }
Nick_F
  • 1,103
  • 2
  • 13
  • 30
  • 1
    What is `sJsonCode`? – Patrick Hofman Jan 21 '18 at 11:28
  • It's json code from a web page. If I check the code in a browser, they display the single quotes correctly. – Nick_F Jan 21 '18 at 11:34
  • 1
    How about this post :https://stackoverflow.com/questions/2477452/%C3%A2%E2%82%AC-showing-on-page-instead-of – Ole EH Dufour Jan 21 '18 at 11:41
  • 2
    Yes, that solved my problem. I was using a WebClient and I had to set the encoding property: client.Encoding = System.Text.Encoding.UTF8; You can provide an answer and I will accept your answer. – Nick_F Jan 21 '18 at 11:45
  • Patrick, your question was valuable, but I did not realize at the time. If I was accessing the jscode through Google Chrome, the characters were showing up correctly. But when I was using the WebClient in my program to download the source code, I did not realize the characters were incorrect anymore. – Nick_F Jan 21 '18 at 11:51

0 Answers0