调用接口 返回的地址为\/apps\/\u6211\u7684\u5b58\u50a8\/1.jpg正常的应该是 ↓/apps/我的存储/1.jpg请问一下 中间的这个\u6211\u7684\u5b58\u50a8 怎么转换成 "我的存储"这几个正常的中文呢?

解决方案 »

  1.   

    string str = @"\/apps\/\u6211\u7684\u5b58\u50a8\/1.jpg";
                    str = Regex.Replace(str, @"\\u([\w]{2})([\w]{2})", a => {
                        byte[] bts = new byte[2];
                        bts[0] = (byte)int.Parse(a.Groups[2].Value, NumberStyles.HexNumber);
                        bts[1] = (byte)int.Parse(a.Groups[1].Value, NumberStyles.HexNumber);
                        return Encoding.Unicode.GetString(bts);
                    });
                    //\\/apps\\/我的存储\\/1.jpg
      

  2.   

     string str = @"/apps/\u6211\u7684\u5b58\u50a8/1.jpg";
                    str = Regex.Replace(str, @"\\u([\w]{2})([\w]{2})", a => {
                        byte[] bts = new byte[2];
                        bts[0] = (byte)int.Parse(a.Groups[2].Value, NumberStyles.HexNumber);
                        bts[1] = (byte)int.Parse(a.Groups[1].Value, NumberStyles.HexNumber);
                        return Encoding.Unicode.GetString(bts);
                    });
                    // /apps/我的存储/1.jpg
      

  3.   


        public class UnicodeHelper
        {
            public static string Decode(string str)
            {
                Regex regex = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
                return regex.Replace(str, delegate(Match m)
                {
                    char ch = (char)Convert.ToInt32(m.Groups[1].Value, 0x10);
                    return ch.ToString();
                });
            }
        }
      

  4.   

    调用。string str = @"/apps/\u6211\u7684\u5b58\u50a8/1.jpg";
    string str2=UnicodeHelper.Decode(str);