Пример #1
0
        /// <summary>
        /// 使用正则+扩展方法GetJson*  Regex.Match
        /// </summary>
        /// <param name="i"></param>
        public void GetJsonExtensionsFromJson(int i = 0)
        {
            Action <bool> action = (p) => {
                string jsoninfo = _jsoninfo.Replace(":200,", ":" + Rand.RndNum(4) + ",");
                mrinfo mr       = new mrinfo();
                mr.status = jsoninfo.GetJsonInt("status");
                mr.act    = jsoninfo.GetJsonString("act");
                channel cha = new channel();
                cha.c_content      = jsoninfo.GetJsonString("c_content");
                cha.c_channel_code = jsoninfo.GetJsonString("c_channel_code");
                cha.c_optc         = jsoninfo.GetJsonString("c_optc");
                cha.c_mobile       = jsoninfo.GetJsonString("c_mobile");
                cha.m_amount       = jsoninfo.GetJsonDecimal("m_amount");
                cha.t_collect_time = jsoninfo.GetJsonString("t_collect_time").ToDateTime();
                cha.c_link_id      = jsoninfo.GetJsonString("c_link_id");
                mr.value           = cha;
                if (p)
                {
                    Trace.WriteLine("GetJsonExtensions:");
                    Trace.WriteLine(mr.ToJson());
                }
            };

            if (i < 1)
            {
                action(true);
            }
            else
            {
                string data = ActionExtensions.Time(() => action(false), "GetJsonExtensions", i);
                Trace.WriteLine(data.Replace("<br />", Environment.NewLine));
            }
        }
Пример #2
0
        /// <summary>
        /// 使用正则匹配单个记录 Regex.Match + Replace
        /// </summary>
        /// <param name="i"></param>
        public void GetMatchingValue2FromJson(int i = 0)
        {
            Action <bool> action = (p) => {
                string jsoninfo = _jsoninfo.Replace(":200,", ":" + Rand.RndNum(4) + ",");
                mrinfo mr       = new mrinfo();
                mr.status = jsoninfo.GetMatchingValue("\"status\":(\\d+)", "\"status\":", ",").ToInt(0);
                mr.act    = jsoninfo.GetMatchingValue("\"act\":\"(.+?)\"", "\"act\":\"", "\"");
                channel cha = new channel();
                cha.c_content      = jsoninfo.GetMatchingValue("\"c_content\":\"(.+?)\"", "\"c_content\":\"", "\"");
                cha.c_channel_code = jsoninfo.GetMatchingValue("\"c_channel_code\":\"(.+?)\"", "\"c_channel_code\":\"", "\"");
                cha.c_optc         = jsoninfo.GetMatchingValue("\"c_optc\":\"(.+?)\"", "\"c_optc\":\"", "\"");
                cha.c_mobile       = jsoninfo.GetMatchingValue("\"c_mobile\":\"(.+?)\"", "\"c_mobile\":\"", "\"");
                cha.m_amount       = jsoninfo.GetMatchingValue("\"m_amount\":(\\d+)", "\"m_amount\":", ",").ToInt(0);
                cha.t_collect_time = jsoninfo.GetMatchingValue("\"t_collect_time\":\"(.+?)\"", "\"t_collect_time\":\"", "\"").ToDateTime();
                cha.c_link_id      = jsoninfo.GetMatchingValue("\"c_link_id\":\"(.+?)\"", "\"c_link_id\":\"", "\"");
                mr.value           = cha;
                if (p)
                {
                    Trace.WriteLine("GetMatchingValue2:");
                    Trace.WriteLine(mr.ToJson());
                }
            };

            if (i < 1)
            {
                action(true);
            }
            else
            {
                string data = ActionExtensions.Time(() => action(false), "GetMatchingValue2", i);
                Trace.WriteLine(data.Replace("<br />", Environment.NewLine));
            }
        }
Пример #3
0
        /// <summary>
        /// System.Web.Script.Serialization.JavaScriptSerializer
        /// </summary>
        /// <param name="i"></param>
        public void SerializationToJson(int i = 0)
        {
            Action <bool> action = (p) => {
                string json = tojson.ToJson();
                if (p)
                {
                    Trace.WriteLine("Serialization:");
                    Trace.WriteLine(json);
                }
            };

            if (i < 1)
            {
                action(true);
            }
            else
            {
                string data = ActionExtensions.Time(() => action(false), "Serialization", i);
                Trace.WriteLine(data.Replace("<br />", Environment.NewLine));
            }
        }
Пример #4
0
        /// <summary>
        /// 第三方库FastJson
        /// </summary>
        /// <param name="i"></param>
        public void FastJsonFromJson(int i = 0)
        {
            Action <bool> action = (p) => {
                string jsoninfo = _jsoninfo.Replace(":200,", ":" + Rand.RndNum(4) + ",");
                mrinfo mr       = JSON.Instance.ToObject <mrinfo>(jsoninfo);
                if (p)
                {
                    Trace.WriteLine("FastJson:");
                    Trace.WriteLine(mr.ToJson());
                }
            };

            if (i < 1)
            {
                action(true);
            }
            else
            {
                string data = ActionExtensions.Time(() => action(false), "FastJson", i);
                Trace.WriteLine(data.Replace("<br />", Environment.NewLine));
            }
        }
Пример #5
0
        /// <summary>
        /// 第三方库Newtonsoft.Json
        /// </summary>
        /// <param name="i"></param>
        public void NewtonsoftJsonFromJson(int i = 0)
        {
            Action <bool> action = (p) => {
                string jsoninfo = _jsoninfo.Replace(":200,", ":" + Rand.RndInt(1, 1000) + ",");
                mrinfo mr       = JsonConvert.DeserializeObject <mrinfo>(jsoninfo);
                if (p)
                {
                    Trace.WriteLine("NewtonsoftJson:");
                    Trace.WriteLine(mr.ToJson());
                }
            };

            if (i < 1)
            {
                action(true);
            }
            else
            {
                string data = ActionExtensions.Time(() => action(false), "NewtonsoftJson", i);
                Trace.WriteLine(data.Replace("<br />", Environment.NewLine));
            }
        }