1Product product = new Product();
2product.Name = "Apple";
3product.Expiry = new DateTime(2008, 12, 28);
4product.Price = 3.99M;
5product.Sizes = new string[] { "Small", "Medium", "Large" };
6
7string json = JsonConvert.SerializeObject(product);
8//{
9// "Name": "Apple",
10// "Expiry": "2008-12-28T00:00:00",
11// "Price": 3.99,
12// "Sizes": [
13// "Small",
14// "Medium",
15// "Large"
16// ]
17//}
18
19Product deserializedProduct = JsonConvert.DeserializeObject<Product>(json);
1dynamic stuff = JsonConvert.DeserializeObject("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");
2string name = stuff.Name;
3string address = stuff.Address.City;
4// Or using Newtonsoft.Json.Linq
5dynamic stuff = JObject.Parse("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");
6string name = stuff.Name;
7string address = stuff.Address.City;
1const json = '{"result":true, "count":42}';
2const obj = JSON.parse(json);
3
4console.log(obj.count);
5// expected output: 42
6
7console.log(obj.result);
8// expected output: true