C# UTF8 output keep encoded characters intact

Posted by Stefan Pohl on Stack Overflow See other posts from Stack Overflow or by Stefan Pohl
Published on 2010-05-29T23:47:45Z Indexed on 2010/05/29 23:52 UTC
Read the original article Hit count: 515

Filed under:
|

Hello, i have a very simple question I can't seem to get my head around.

I have a properly encoded UTF8-String I parse into a JObject with Json.NET, fiddle around with some values and write it to the commandline, keeping the encoded characters intact.

Everything works great except for the keeping the encoded characters intact part.

Code:

var json = "{roster: [[\"Tulg\u00f4r\", 990, 1055]]}";
var j = JObject.Parse(json);
for (int i = 0; i < j["roster"].Count(); i++)
{
    j["roster"][i][1] = ((int)j["roster"][i][1]) * 3;
    j["roster"][i][2] = ((int)j["roster"][i][2]) * 3;
}
Console.WriteLine(JsonConvert.SerializeObject(j, Formatting.None));

Actual Output:

{"roster":[["Tulgôr",2970,3165]]}

Desired Output:

{"roster":[["Tulg\u00f4r",2970,3165]]}

It seems like my phrasing in Google is inappropriate since nothing useful came up. I'm sure it's something uber-easy and i will feel pretty stupid afterwards. :)

© Stack Overflow or respective owner

Related posts about c#

Related posts about utf8