Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# : Change String Encoding?

I'm struggling with the encoding of one of my string.

On a Mail Sending WS, I'm receiving a bad string containing "�" instead of "é" (that's what I'm seeing in the Debug Mode of Visual Studio at least). The character comes from some JSON that is deserialized when entering the WS into my DTO.

Changing the Content-Type of the JSON is not solving the thing. So I thought I'll change the encoding of my string by myself, because the JSON encoding thing seems like a VS deserialization issue (I started a thread here if one of you guys want to take a look at it).

I tried :

Encoding iso = Encoding.GetEncoding("ISO-8859-1");
Encoding defaultEncoding = Encoding.Default;
byte[] bytes = defaultEncoding.GetBytes(messedUpString);
byte[] isoBytes = Encoding.Convert(defaultEncoding, iso, bytes);
cleanString = iso.GetString(isoBytes);

Or :

byte[] bytes = Encoding.Default.GetBytes(messedUpString);
cleanString = Encoding.UTF8.GetString(bytes);

And it's not really effective... I get rid of the "�" char, which is the nice part, but I'm receiving in the cleanString "?" instead of the expected "é", and this in not really nice, or at least, the expected behavior.

like image 842
Gaëtan Avatar asked Feb 15 '26 07:02

Gaëtan


1 Answers

In fact, every thing was fine in my application.

I used SOAPUI to test, and this was my error. I downloaded some rest plugin for my browser, try from there, and everything worked.

Thanks for the help though @MattiVirkkunen

like image 55
Gaëtan Avatar answered Feb 16 '26 20:02

Gaëtan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!