| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System;
- using LitJson;
- namespace ETHotfix
- {
- public static class JsonHelper
- {
- public static string ToJson(object obj)
- {
- return JsonMapper.ToJson(obj);
- }
- public static T FromJson<T>(string str)
- {
- T t = JsonMapper.ToObject<T>(str);
- ISupportInitialize iSupportInitialize = t as ISupportInitialize;
- if (iSupportInitialize == null)
- {
- return t;
- }
- iSupportInitialize.EndInit();
- return t;
- }
- public static object FromJson(Type type, string str)
- {
- object t = JsonMapper.ToObject(type, str);
- ISupportInitialize iSupportInitialize = t as ISupportInitialize;
- if (iSupportInitialize == null)
- {
- return t;
- }
- iSupportInitialize.EndInit();
- return t;
- }
- public static T Clone<T>(T t)
- {
- return FromJson<T>(ToJson(t));
- }
- }
- }
|