Click or drag to resize
Json.NETDeserialize JSON from a file
 

This sample deserializes JSON retrieved from a file.

Sample
Types
1public class Movie
2{
3    public string Name { get; set; }
4    public int Year { get; set; }
5}
Usage
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}