using Newtonsoft.Json.Converters; using Newtonsoft.Json; namespace DS.WMS.PrintApi.Utils { public class JsonHelper { private static JsonHelper _jsonHelper = new JsonHelper(); public static JsonHelper Instance { get { return _jsonHelper; } } public string Serialize(object obj) { return JsonConvert.SerializeObject(obj, new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }); } public string SerializeByConverter(object obj, params JsonConverter[] converters) { return JsonConvert.SerializeObject(obj, converters); } public T Deserialize(string input) { return JsonConvert.DeserializeObject(input); } public T DeserializeByConverter(string input, params JsonConverter[] converter) { return JsonConvert.DeserializeObject(input, converter); } public T DeserializeBySetting(string input, JsonSerializerSettings settings) { return JsonConvert.DeserializeObject(input, settings); } private object NullToEmpty(object obj) { return null; } } }