C# 将文本转换为unicode字符串

C# 将文本转换为unicode字符串,c#,.net,unicode,text,C#,.net,Unicode,Text,我必须处理如下所示的JSON文件: \u0432\u043b\u0430\u0434\u043e\u043c <b>\u043f\u0443\u0442\u0438\u043c<\/b> \u043d\u0430\u0447 \u0432\u043b\u0430\u0434\u043e\u043c\u043f\u0443\u0442\u0438\u043c\u043d\u0430\u0447 不幸的是,我不确定这种编码是如何调用的 我想将其转换为.NET Unicod

我必须处理如下所示的JSON文件:

\u0432\u043b\u0430\u0434\u043e\u043c <b>\u043f\u0443\u0442\u0438\u043c<\/b> \u043d\u0430\u0447
\u0432\u043b\u0430\u0434\u043e\u043c\u043f\u0443\u0442\u0438\u043c\u043d\u0430\u0447
不幸的是,我不确定这种编码是如何调用的


我想将其转换为.NET Unicode字符串。最简单的方法是什么?

这是俄语字母表的Unicode字符。 尝试简单地将这一行放在VisualStudio中,它将解析它

string unicodeString = "\u0432\u043b\u0430\u0434\u043e\u043c";
或者,如果要将此字符串转换为其他编码,例如utf8,请尝试以下代码:

static void Main()
    {
        string unicodeString = "\u0432\u043b\u0430\u0434\u043e\u043c <b>\u043f\u0443\u0442\u0438\u043c<\b> \u043d\u0430\u0447";
        // Create two different encodings.
        Encoding utf8 = Encoding.UTF8;
        Encoding unicode = Encoding.Unicode;

        // Convert the string into a byte[].
        byte[] unicodeBytes = unicode.GetBytes(unicodeString);

        // Perform the conversion from one encoding to the other.
        byte[] utf8Bytes = Encoding.Convert(unicode, utf8, unicodeBytes);

        // Convert the new byte[] into a char[] and then into a string.
        // This is a slightly different approach to converting to illustrate
        // the use of GetCharCount/GetChars.
        char[] asciiChars = new char[utf8.GetCharCount(utf8Bytes, 0, utf8Bytes.Length)];
        utf8.GetChars(utf8Bytes, 0, utf8Bytes.Length, asciiChars, 0);
        string asciiString = new string(asciiChars);

        // Display the strings created before and after the conversion.
        Console.WriteLine("Original string: {0}", unicodeString);
        Console.WriteLine("Ascii converted string: {0}", asciiString);
        Console.ReadKey();
    }
static void Main()
{
字符串unicodeString=“\u0432\u043b\u0430\u0434\u043e\u043c\u043f\u0443\u0442\u0438\u043c\u043d\u0430\u0447”;
//创建两种不同的编码。
Encoding utf8=Encoding.utf8;
Encoding unicode=Encoding.unicode;
//将字符串转换为字节[]。
字节[]unicodeBytes=unicode.GetBytes(unicodeString);
//执行从一种编码到另一种编码的转换。
byte[]utf8Bytes=Encoding.Convert(unicode、utf8、unicode字节);
//将新字节[]转换为字符[],然后转换为字符串。
//这是一种稍微不同的转换方法来说明
//GetCharCount/GetChars的使用。
char[]ascichars=new char[utf8.GetCharCount(utf8Bytes,0,utf8Bytes.Length)];
GetChars(utf8Bytes,0,utf8Bytes.Length,ascichars,0);
字符串ascistring=新字符串(ascichars);
//显示转换前后创建的字符串。
WriteLine(“原始字符串:{0}”,unicodeString);
WriteLine(“Ascii转换字符串:{0}”,asciiString);
Console.ReadKey();
}
代码取自