PapaMortality
Casting Error, Not sure why. Newtonsoft.Json;
using System;
using Newtonsoft.Json;
namespace Cereal
{
public class Program
{
public static void Main(string[] args)
{
// Person p = new Person{
// First = "John",
// Middle = "Doodle",
// Last = "Doe",
// Age = 23
// };
// var r = p.Serialize("test.json");
// Console.WriteLine($"{r}");
Person np = Serializer.Deserialize<Person>("test.json");
Console.WriteLine($"{np}");
}
}
}
// This is in the Serializer class
public static T Deserialize<T>(string filePath)
{
string content;
using (StreamReader sr = new(filePath))
{
content = sr.ReadToEnd();
}
var settings = GetJsonSettings();
Console.WriteLine($"{content}");
return (T)JsonConvert.DeserializeObject<T>(content, settings);
}
using System;
using Newtonsoft.Json;
namespace Cereal
{
public class Program
{
public static void Main(string[] args)
{
// Person p = new Person{
// First = "John",
// Middle = "Doodle",
// Last = "Doe",
// Age = 23
// };
// var r = p.Serialize("test.json");
// Console.WriteLine($"{r}");
Person np = Serializer.Deserialize<Person>("test.json");
Console.WriteLine($"{np}");
}
}
}
// This is in the Serializer class
public static T Deserialize<T>(string filePath)
{
string content;
using (StreamReader sr = new(filePath))
{
content = sr.ReadToEnd();
}
var settings = GetJsonSettings();
Console.WriteLine($"{content}");
return (T)JsonConvert.DeserializeObject<T>(content, settings);
}
28 replies