当前位置: 首页>>代码示例>>C#>>正文


C# System.Web.Script.Serialization.JavaScriptSerializer.GetType方法代码示例

本文整理汇总了C#中System.Web.Script.Serialization.JavaScriptSerializer.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# System.Web.Script.Serialization.JavaScriptSerializer.GetType方法的具体用法?C# System.Web.Script.Serialization.JavaScriptSerializer.GetType怎么用?C# System.Web.Script.Serialization.JavaScriptSerializer.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Script.Serialization.JavaScriptSerializer的用法示例。


在下文中一共展示了System.Web.Script.Serialization.JavaScriptSerializer.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FathersTest

        // Note: fathers.json.txt was generated using:
        // http://experiments.mennovanslooten.nl/2010/mockjson/tryit.html
        // avg: file size ~ parse exec time (on Lenovo Win7 PC, i5, 2.50GHz, 6Gb)
        // small.json.txt... avg: 4kb... parsed in ~1ms
        // fathers.json.txt... avg: 12mb... parsed in ~3sec (30k msg... => 10k msg/sec)
        // huge.json.txt... avg: 180mb... parsed in ~20sec
        public static void FathersTest()
        {
            Console.Clear();
            string json = System.IO.File.ReadAllText(FATHERS_TEST_FILE_PATH);
            Console.WriteLine("Fathers Test - JSON parse... {0} kb ({1} mb)", (int)(json.Length / 1024), (int)(json.Length / (1024 * 1024)));
            Console.WriteLine();

            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer
            {
                MaxJsonLength = int.MaxValue
            };
            Console.WriteLine("\tParsed by {0} in...", serializer.GetType().FullName);
            DateTime start1 = DateTime.Now;
            var msObj = serializer.DeserializeObject(json);
            Console.WriteLine("\t\t{0} ms", (int)DateTime.Now.Subtract(start1).TotalMilliseconds);
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("\tParsed by {0} in...", typeof(Parser).FullName);
            DateTime start2 = DateTime.Now;
            var myObj = JSON.Map(null as object).FromJson(json);
            Console.WriteLine("\t\t{0} ms", (int)DateTime.Now.Subtract(start2).TotalMilliseconds);
            Console.WriteLine();

            Console.WriteLine("Press '1' to inspect our result object,\r\nany other key to inspect Microsoft's JS serializer result object...");
            var parsed = ((Console.ReadKey().KeyChar == '1') ? myObj : msObj);

            IList<object> fathers = parsed.Object()["fathers"].Array();
            Console.WriteLine();
            Console.WriteLine("Found : {0} fathers", fathers.Count);
            Console.WriteLine();
            Console.WriteLine("Press a key to list them...");
            Console.WriteLine();
            Console.ReadKey();
            Console.WriteLine();
            foreach (object father in fathers)
            {
                var name = (string)father.Object()["name"];
                var sons = father.Object()["sons"].Array();
                var daughters = father.Object()["daughters"].Array();
                Console.WriteLine("{0}", name);
                Console.WriteLine("\thas {0} son(s), and {1} daughter(s)", sons.Count, daughters.Count);
                Console.WriteLine();
            }
            Console.WriteLine("Press a key...");
            Console.ReadKey();
        }
开发者ID:ysharplanguage,项目名称:ysharp,代码行数:53,代码来源:BasicTests.cs


注:本文中的System.Web.Script.Serialization.JavaScriptSerializer.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。