首页 > Web开发 > 详细

Json转Unicode

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

输入为带有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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!