You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB
C#

4 months ago
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<T>(string input)
{
return JsonConvert.DeserializeObject<T>(input);
}
public T DeserializeByConverter<T>(string input, params JsonConverter[] converter)
{
return JsonConvert.DeserializeObject<T>(input, converter);
}
public T DeserializeBySetting<T>(string input, JsonSerializerSettings settings)
{
return JsonConvert.DeserializeObject<T>(input, settings);
}
private object NullToEmpty(object obj)
{
return null;
}
}
}