. Net (c #) Chinese Character and Unicode encoding are mutually converted,
{"Tilte": "\u535a\u5ba2\u56ed", "Href": "http://www.cnblogs.com"}
This json string is often used to convert the Chinese characters into Unicode codes.
Unicode encoding:
UNICODE encoding of Chinese characters, such as "King", which becomes "\ King". UNICODE characters start with \ u and are followed by four numbers or letters, all characters are hexadecimal numbers. Each two character represents a number less than 256. A Chinese character is composed of two characters, so it is easy to understand that "738b" is two characters, namely "73" and "8b ". However, when converting the UNICODE character encoding content to Chinese characters, the characters are processed forward from the back,You need to combine characters in the order of "8b" and "73" to obtain Chinese characters..
Unicode/Chinese character conversion implementation:
/// <Summary> // convert the string to Unicode // </summary> /// <param name = "source"> source string </ param> // <returns> Unicode encoded string </returns> public static string String2Unicode (string source) {byte [] bytes = Encoding. unicode. getBytes (source); StringBuilder stringBuilder = new StringBuilder (); for (int I = 0; I <bytes. length; I + = 2) {stringBuilder. appendFormat ("\ u {0} {1}", bytes [I + 1]. toString ("x "). padLeft (2, '0'), bytes [I]. toString ("x "). padLeft (2, '0');} return stringBuilder. toString ();} /// <summary> // convert Unicode to string /// </summary> /// <param name = "source"> Unicode-encoded string </param>/ // <returns> normal string </returns> public static string Unicode2String (string source) {return new Regex (@ "\ u ([0-9A-F] {4})", RegexOptions. ignoreCase | RegexOptions. compiled ). replace (source, x => string. empty + Convert. toChar (Convert. toUInt16 (x. result ("$1"), 16 )));}