how to convert json file to c# object code example
Example 1: c# json from file to object
public class Movie
{
public string Name { get; set; }
public int Year { get; set; }
}
Movie movie1 = JsonConvert.DeserializeObject<Movie>(File.ReadAllText(@"c:\movie.json"));
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
Example 2: c# json convert
jsonString = File.ReadAllText(fileName);
weatherForecast = JsonSerializer.Deserialize<WeatherForecast>(jsonString);