Car/Assets/Plugin/YogiGameCore/FullSerializer/Source/JsonHelper.cs

22 lines
717 B
C#
Raw Normal View History

2024-12-31 07:57:41 +08:00
namespace FullSerializer
{
public class JsonHelper
{
public static string Serialize<T>(T data)
{
var fsSerializer = new fsSerializer();
fsSerializer.TrySerialize(typeof(T), data, out var fsData)
.AssertSuccessWithoutWarnings();
return fsJsonPrinter.PrettyJson(fsData);
}
public static T Deserialize<T>(string jsonData) where T : new()
{
var result = new T();
var fsSerializer = new fsSerializer();
var fsData = fsJsonParser.Parse(jsonData);
fsSerializer.TryDeserialize(fsData, ref result).AssertSuccessWithoutWarnings();
return result;
}
}
}