convert class to json c# and save to file
string fileName = "WeatherForecast.json";
string jsonString = JsonSerializer.Serialize<WeatherForecast>(weatherForecast);
File.WriteAllText(fileName, jsonString);
convert class to json c# and save to file
string fileName = "WeatherForecast.json";
string jsonString = JsonSerializer.Serialize<WeatherForecast>(weatherForecast);
File.WriteAllText(fileName, jsonString);
convert class to json c# and save to file
using System;
using System.Text.Json;
namespace SerializeWithGenericParameter
{
public class WeatherForecast
{
public DateTimeOffset Date { get; set; }
public int TemperatureCelsius { get; set; }
public string Summary { get; set; }
}
public class Program
{
public static void Main()
{
var weatherForecast = new WeatherForecast
{
Date = DateTime.Parse("2019-08-01"),
TemperatureCelsius = 25,
Summary = "Hot"
};
string jsonString = JsonSerializer.Serialize<WeatherForecast>(weatherForecast);
Console.WriteLine(jsonString);
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us