本文整理汇总了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();
}