using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GraphicsStudy { public static class JsonUtils { private static readonly List JsonConverters = new List() { new Json.XYZConverter(), new Json.LineConverter(), new Json.TransformConvert(), new Json.ElementIdConverter() }; /// /// JSON序列化 /// /// /// public static string ObjectToJson(object obj) { JsonSerializerSettings jsSettings = new JsonSerializerSettings(); jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; return JsonConvert.SerializeObject(obj/*, JsonConverters.ToArray()*/); } /// /// JSON反序列化 /// /// /// public static T JsonToObject(string jsonStr) where T : class { return JsonConvert.DeserializeObject(jsonStr/*, JsonConverters.ToArray()*/); } } }