1using Newtonsoft.Json;
2
3var jsonString = JsonConvert.SerializeObject(obj);
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}
1var resultCon = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonStr);
2
3//or
4string json = "{\"ID\": 1, \"Name\": \"Abdullah\"}";
5User user = JsonConvert.DeserializeObject<User>(json);
6/*
7public class User
8{
9 public int ID { get; set; }
10 public string Name { get; set; }
11}
12*/