1using System.Text.Json;
2
3//Serialize
4var jsonString = JsonSerializer.Serialize(yourObject);
5
6// Deserialize
7var obj = JsonSerializer.Deserialize<YourObject>(stringValue);
1using System;
2using System.Web.Script.Serialization;
3
4public class MyDate
5{
6 public int year;
7 public int month;
8 public int day;
9}
10
11public class Lad
12{
13 public string firstName;
14 public string lastName;
15 public MyDate dateOfBirth;
16}
17
18class Program
19{
20 static void Main()
21 {
22 var obj = new Lad
23 {
24 firstName = "Markoff",
25 lastName = "Chaney",
26 dateOfBirth = new MyDate
27 {
28 year = 1901,
29 month = 4,
30 day = 30
31 }
32 };
33 var json = new JavaScriptSerializer().Serialize(obj);
34 Console.WriteLine(json);
35 }
36}