1// read file into a string and deserialize JSON to a type
2Movie movie1 = JsonConvert.DeserializeObject<Movie>(File.ReadAllText(@"c:\movie.json"));
3
4// deserialize JSON directly from a file
5using (StreamReader file = File.OpenText(@"c:\movie.json"))
6{
7 JsonSerializer serializer = new JsonSerializer();
8 Movie movie2 = (Movie)serializer.Deserialize(file, typeof(Movie));
9}
1public class Movie
2{
3 public string Name { get; set; }
4 public int Year { get; set; }
5}
6// read file into a string and deserialize JSON to a type
7Movie movie1 = JsonConvert.DeserializeObject<Movie>(File.ReadAllText(@"c:\movie.json"));
8
9// deserialize JSON directly from a file
10using (StreamReader file = File.OpenText(@"c:\movie.json"))
11{
12 JsonSerializer serializer = new JsonSerializer();
13 Movie movie2 = (Movie)serializer.Deserialize(file, typeof(Movie));
14}
15string name = movie2.Name;
16int year = movie2.Year