Skip to content

Instantly share code, notes, and snippets.

@voquanghoa
Created November 27, 2017 04:22
Show Gist options
  • Save voquanghoa/c37f3d9df60f83ace2d551f81017af56 to your computer and use it in GitHub Desktop.
Save voquanghoa/c37f3d9df60f83ace2d551f81017af56 to your computer and use it in GitHub Desktop.
public static void SaveJson<T>(List<T> data, string directory)
{
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
var fileName = $"{typeof(T).Name}s.json";
var filePath = Path.Combine(directory, fileName);
var json = JsonConvert.SerializeObject(data);
File.WriteAllText(filePath, json);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment