Answers for "c# json from file to object"

4

c# read json file into object

// read file into a string and deserialize JSON to a type
Movie movie1 = JsonConvert.DeserializeObject<Movie>(File.ReadAllText(@"c:\movie.json"));

// deserialize JSON directly from a file
using (StreamReader file = File.OpenText(@"c:\movie.json"))
{
    JsonSerializer serializer = new JsonSerializer();
    Movie movie2 = (Movie)serializer.Deserialize(file, typeof(Movie));
}
Posted by: Guest on September-29-2020
3

c# json from file to object

public class Movie
{
    public string Name { get; set; }
    public int Year { get; set; }
}
// read file into a string and deserialize JSON to a type
Movie movie1 = JsonConvert.DeserializeObject<Movie>(File.ReadAllText(@"c:\movie.json"));

// deserialize JSON directly from a file
using (StreamReader file = File.OpenText(@"c:\movie.json"))
{
    JsonSerializer serializer = new JsonSerializer();
    Movie movie2 = (Movie)serializer.Deserialize(file, typeof(Movie));
}
string name = movie2.Name;
int year = movie2.Year
Posted by: Guest on February-11-2021

Code answers related to "c# json from file to object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language