URL乱码转换文字

8/3/2015来源:C#应用人气:3071

URL乱码转换文字

输入为带有json格式的文本,输出正常文本。

//20130625 by zhangyl PRivate string ConvertToString(string input)         {             input = input.Replace("\\\"", "\"");             input = input.Replace("\\/", "/");             string result;             if (!input.Contains("\\u"))             {                 result = input;             }             else             {                 StringBuilder stringBuilder = new StringBuilder();                 if (input.IndexOf("\\u") > 0)                 {                     stringBuilder.Append(input.Substring(0, input.IndexOf("\\u")));                     input = input.Substring(input.IndexOf("\\u"));                 }                 if (!string.IsNullOrEmpty(input))                 {                     string[] array = input.Split(new string[]                     {                         "\\u"                     }, StringSplitOptions.RemoveEmptyEntries);                     string[] array2 = array;                     for (int i = 0; i < array2.Length; i++)                     {                         string text = array2[i];                         if (text.Length > 4)                         {                             string arg = text.Substring(4);                             stringBuilder.Append((char)int.Parse(text.Substring(0, 4), NumberStyles.HexNumber) + arg);                         }                         else                         {                             if (text.Length == 4)                             {                                 stringBuilder.Append((char)int.Parse(text, NumberStyles.HexNumber));                             }                             else                             {                                 if (text.Length < 4 && text.Length > 0)                                 {                                     stringBuilder.Append(text);                                 }                             }                         }                     }                 }                 result = stringBuilder.ToString();             }             return result;         }