diff --git a/Assets/TEngine/Runtime/Utility/NewtonsoftJsonHelper.cs b/Assets/TEngine/Runtime/Utility/NewtonsoftJsonHelper.cs new file mode 100644 index 00000000..ed2f028d --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/NewtonsoftJsonHelper.cs @@ -0,0 +1,37 @@ +namespace TEngine +{ + public class NewtonsoftJsonHelper : Utility.Json.IJsonHelper + { + /// + /// 将对象序列化为 JSON 字符串。 + /// + /// 要序列化的对象。 + /// 序列化后的 JSON 字符串。 + public string ToJson(object obj) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(obj); + } + + /// + /// 将 JSON 字符串反序列化为对象。 + /// + /// 对象类型。 + /// 要反序列化的 JSON 字符串。 + /// 反序列化后的对象。 + public T ToObject(string json) + { + return Newtonsoft.Json.JsonConvert.DeserializeObject(json); + } + + /// + /// 将 JSON 字符串反序列化为对象。 + /// + /// 对象类型。 + /// 要反序列化的 JSON 字符串。 + /// 反序列化后的对象。 + public object ToObject(System.Type objectType, string json) + { + return Newtonsoft.Json.JsonConvert.DeserializeObject(json, objectType); + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Utility/NewtonsoftJsonHelper.cs.meta b/Assets/TEngine/Runtime/Utility/NewtonsoftJsonHelper.cs.meta new file mode 100644 index 00000000..95eedce3 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/NewtonsoftJsonHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 38484765ede44acc840c664a828ca6ff +timeCreated: 1687360419 \ No newline at end of file