public static void Main() { EmitHelper.SwitchDoNotVerify = true; FastObjectRW.DefaultOptions &= ~FastObjectRWOptions.IgnoreCase; var catalog = new CatalogModel().GetObject(); var json = JsonFormatter.SerializeObject(catalog, JsonFormatterOptions.IgnoreNull | JsonFormatterOptions.IgnoreZero | JsonFormatterOptions.IgnoreEmptyString); while (true) { fixed(char *chars = json) { var stopwatch = Stopwatch.StartNew(); for (int i = 0; i < 100; i++) { ReadJson(JsonFormatter.CreateJsonReader(chars, json.Length)); } Console.WriteLine(stopwatch.ElapsedMilliseconds); } } }
public void ReaderTest() { var hGCache = new HGlobalCache <char>(); JsonFormatter.SerializeObject(new object[] { 123, "Dogwei", true, null, new { Id = 123 } }, hGCache); var jsonReader = JsonFormatter.CreateJsonReader(hGCache); AreEqual(jsonReader.GetToken(), JsonToken.Array); AreEqual(jsonReader.TryReadBeginArray(), true); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.Number); AreEqual(jsonReader.ReadInt32(), 123); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.String); AreEqual(jsonReader.ReadString(), "Dogwei"); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.Boolean); AreEqual(jsonReader.ReadBoolean(), true); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.Null); AreEqual(jsonReader.DirectRead(), null); AreEqual(jsonReader.TryReadEndArray(), false); AreEqual(jsonReader.GetToken(), JsonToken.Object); AreEqual(JsonFormatter.SerializeObject(ValueInterface <Dictionary <string, object> > .ReadValue(jsonReader)), "{\"Id\":123}"); AreEqual(jsonReader.TryReadEndArray(), true); AreEqual(jsonReader.GetToken(), JsonToken.End); }