zoukankan      html  css  js  c++  java
  • vs2003 序列化json

    /// <summary>
        /// JSON 的摘要说明。
        /// </summary>
        public class JSON
        {
            private static readonly string Json_A = "3A3B1A16-F697-4a32-A0B0-2515BB4692F5";
            private static readonly string Json_B = "274BEBC4-2482-4426-9A23-C32D25F7615B";
            private static readonly string Json_C = "5ACEB051-8505-4e8c-ACE7-91DE1D101190";
            private static readonly string Json_D = "DEF0006D-650D-497c-9D27-40A20E337970";
    
            public static object JsonDecode(string srcString)
            {
                srcString = srcString.Trim();
                object result = null;
    
                srcString = srcString.Replace("},{", Json_A);
                srcString = srcString.Replace("],[", Json_B);
                srcString = srcString.Replace("\",", Json_D);
                srcString = srcString.Replace(",", Json_C);
                srcString = srcString.Replace(Json_D, "\",");
                srcString = srcString.Replace(Json_B, "],[");
                srcString = srcString.Replace(Json_A, "},{");
    
                if (!(srcString == null || srcString == ""))//不空
                {
                    if (srcString.StartsWith("[") && srcString.EndsWith("]"))//序列
                    {
                        srcString = srcString.Substring(1, srcString.Length - 2);
                        ArrayList al = new ArrayList();
                        string[] src = srcString.Split(',');
                        foreach (string s in src)
                        {
                            if (s == null || s == "") continue;
                            string ss=s.Replace(Json_C, ",");
                            al.Add(JsonDecode(ss));
                        }
    
                        result = al;
                    }
                    else if (srcString.StartsWith("{") && srcString.EndsWith("}"))//映射
                    {
                        srcString = srcString.Substring(1, srcString.Length - 2);
                        Hashtable table = new Hashtable();
                        string[] src = srcString.Split(new char[]{','});
                        foreach (string s in src)
                        {
                            string ss = s.Trim().Replace(Json_C, ",");
    
                            if (ss == null || ss == "") continue;
    
                            string key = ss.Trim().Substring(ss.IndexOf('"')+1, ss.IndexOf(':') - ss.IndexOf('"')-2);
                            string @value = ss.Trim().Substring(ss.Trim().IndexOf(':') + 1);
                            table.Add(key, JsonDecode(@value));
                        }
                        result = table;
                    }
                    else //标量
                    {
                        srcString=srcString.Replace(Json_C, ",");
    
                        if ((srcString.StartsWith("'") && srcString.EndsWith("'")) || (srcString.StartsWith("\"") && srcString.EndsWith("\"")))//字符串或时间
                        {
                            try
                            {
                                result = DateTime.Parse(srcString.Substring(0, srcString.Length - 2));//时间
                            }
                            catch//字符串
                            {
                                result = srcString.Substring(1, srcString.Length - 2);
                            }
                        }
                        else if (srcString.IndexOf(".") >= 0)//精度数
                        {
                            try
                            {
                                result = Double.Parse(srcString);
                            }
                            catch//无效数据
                            {
                                result = srcString.Substring(1, srcString.Length - 2);
                            }
                        }
                        else//整数或Bool
                        {
                            try
                            {
                                result = long.Parse(srcString);
                            }
                            catch//Bool 或无效数据
                            {
                                srcString = srcString.ToUpper();
    
                                if (srcString == "TRUE") result = true;
                                else if (srcString == "FALSE") result = false;
                                else result = null;
                            }
                        }
                    }
                }
    
                return result;
            }
        }
  • 相关阅读:
    docker容器,镜像常用操作
    微信小程序登录状态
    微信小程序登录流程图
    GET和POST可传递的值到底有多大?
    php发送请求
    thinkphp 导入微信小程序加密解密库
    thinkphp 随机获取一条数据
    bootstrap row 行间距
    webstorm es6 语法报错
    Laravel
  • 原文地址:https://www.cnblogs.com/honghong75042/p/3077329.html
Copyright © 2011-2022 走看看