Click or drag to resize
Json.NETSerialize with DefaultSettings
 

This sample serializes and deserializes JSON using DefaultSettings.

Sample
Usage
 1// settings will automatically be used by JsonConvert.SerializeObject/DeserializeObject
 2JsonConvert.DefaultSettings = () => new JsonSerializerSettings
 3{
 4    Formatting = Formatting.Indented,
 5    ContractResolver = new CamelCasePropertyNamesContractResolver()
 6};
 7
 8Staff s = new Staff
 9{
10    FirstName = "Eric",
11    LastName = "Example",
12    BirthDate = new DateTime(1980, 4, 20, 0, 0, 0, DateTimeKind.Utc),
13    Department = "IT",
14    JobTitle = "Web Dude"
15};
16
17json = JsonConvert.SerializeObject(s);
18// {
19//   "firstName": "Eric",
20//   "lastName": "Example",
21//   "birthDate": "1980-04-20T00:00:00Z",
22//   "department": "IT",
23//   "jobTitle": "Web Dude"
24// }