码迷,mamicode.com
首页 > Web开发 > 详细

Json转Unicode

时间:2014-08-08 17:44:06      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:style   os   io   for   ar   amp   new   res   

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

 

//20130625 by zhangyl
private string JsonToUnicode(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;
        }

Json转Unicode,布布扣,bubuko.com

Json转Unicode

标签:style   os   io   for   ar   amp   new   res   

原文地址:http://www.cnblogs.com/preacher/p/3899666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!