Answers for "c# write json to file"

-1

how to create json file in c#

//open file stream
using (StreamWriter file = File.CreateText(@"D:\path.txt"))
{
     JsonSerializer serializer = new JsonSerializer();
     //serialize object directly into file stream
     serializer.Serialize(file, _data);
}
Posted by: Guest on October-02-2020
0

c# write json to file

using System.Text.Json;
using System.Text.Json.Serialization;

List<data> _data = new List<data>();
_data.Add(new data()
{
    Id = 1,
    SSN = 2,
    Message = "A Message"
});

using FileStream fileStream = File.Create(@"D:\path.json");
await JsonSerializer.SerializeAsync(createStream, _data);
Posted by: Guest on August-23-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language