public void TypedObjectDeserialization() { Product p = new Product(); p.Name = "Apple"; p.Expiry = new DateTime(2010, 1, 24, 12, 0, 0); p.Price = 3.99M; JsonSerializer serializer = new JsonSerializer(); StringWriter sw = new StringWriter(); using (JsonWriter jsonWriter = new JsonWriter(sw)) { serializer.Serialize(sw, p); } string output = sw.ToString(); using (StringReader sr = new StringReader(output)) { using (JsonReader jr = new JsonReader(sr)) { p = serializer.Deserialize(jr, typeof(Product)) as Product; } } Assert.AreEqual("Apple", p.Name); Assert.AreEqual(new DateTime(2010, 1, 24, 12, 0, 0), p.Expiry); Assert.AreEqual(3.99, p.Price); }
public Store() { Mottos.Add("Hello World"); Mottos.Add("öäüÖÄÜ\\'{new Date(12345);}[222]_µ@²³~"); Mottos.Add(null); Mottos.Add(" "); Product rocket = new Product(); rocket.Name = "Rocket"; rocket.Expiry = new DateTime(2000, 2, 2, 23, 1, 30); Product alien = new Product(); alien.Name = "Alien"; product.Add(rocket); product.Add(alien); }