using System; using UnityEngine; namespace Guru { using Newtonsoft.Json; public static class JsonDataHelper { public static Action ExceptionHandler; public static string ToJsonString(object obj) { try { return JsonConvert.SerializeObject(obj); } catch (Exception e) { ExceptionHandler?.Invoke(e); Debug.LogError(e); } return ""; } public static bool Parse(string json, out T result) { bool success = false; result = default(T); if(string.IsNullOrEmpty(json)) return false; try { result = JsonConvert.DeserializeObject(json); success = true; } catch (Exception e) { ExceptionHandler?.Invoke(e); Debug.LogError(e); } return success; } public static string ToJson(this IJsonData obj) { return ToJsonString((object)obj); } } }