Json转Unicode

输入为带有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,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。