using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.IO; using System.Text; using Newtonsoft.Json; namespace YKMoon.IO { public partial class IOTools { public static bool JsonSave(string path, object jsonObject, string password = "", bool prrety = false) { try { string jsonStr = JsonConvert.SerializeObject(jsonObject, prrety ? Formatting.Indented : Formatting.None); byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(jsonStr); CreateFile(path, fileBytes); return true; } catch(Exception e) { Debug.LogException(e); return false; } } public static bool JsonLoad(string path, ref T jsonObject, string password = "") { try { string jsonStr = GetFileStringByPath(path); if (string.IsNullOrEmpty(jsonStr)) { jsonObject = default(T); return false; } jsonObject = JsonConvert.DeserializeObject(jsonStr); if (jsonObject == null) { return false; } return true; } catch(Exception e) { Debug.LogException(e); return false; } } } }