'Convert JSON containing `\u####` to Unicode string

I would need some help for a string conversion from unicode (\u03a9\u039c\u0395\u0393\u0391) to normal string (ΩΜΕΓΑ). I made a function that theoretically should work but it doesn't work instead. I don't understand what I'm doing wrong. I receive json data with webclient.DownloadString:

{"id": "94401626335", "username": "\u03a9\u039c\u0395\u0393\u0391"}

I get the \u03a9\u039c\u0395\u0393\u0391 and send it to the function:

DecodeFromUtf8(username)

public string DecodeFromUtf8(string utf8String)
        {
            try
            {
                var output = WebUtility.HtmlDecode(utf8String);
                return output;
            }
            catch (Exception ex)
            {
                return utf8String;
            }
        }

the function always returns me: \u03a9\u039c\u0395\u0393\u0391 and not: ΩΜΕΓΑ Why?

i can't use external libraries like system.text.json

Thanks



Solution 1:[1]

use a json deserializer , let it do the work

  public class Ooo {
    public string id { get; set; }
    public string username { get; set; }
  }

    var json = @"{""id"": ""94401626335"", ""username"": ""\u03a9\u039c\u0395\u0393\u0391""}";
    var ooo = System.Text.Json.JsonSerializer.Deserialize<Ooo>(json) ;
    Console.WriteLine("string = " + ooo.username);
}

gives (my console has a glyph misssing, but its show correctly in the debugger)

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1