Answers for "convert class to json c# and save to file"

0

convert class to json c# and save to file

string fileName = "WeatherForecast.json"; 
            string jsonString = JsonSerializer.Serialize<WeatherForecast>(weatherForecast);
            File.WriteAllText(fileName, jsonString);
Posted by: Guest on June-30-2021
0

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);
        }
    }
}
Posted by: Guest on June-30-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language