using Newtonsoft.Json; using System; namespace DS.WMS.PrintApi.Utils { public class JsonConverterLong : JsonConverter { /// /// 是否可以转换 /// /// /// public override bool CanConvert(Type objectType) { return true; } /// /// 读json /// /// /// /// /// /// public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if ((reader.ValueType == null || reader.ValueType == typeof(long?)) && reader.Value == null) { return null; } else { long.TryParse(reader.Value != null ? reader.Value.ToString() : "", out long value); return value; } } /// /// 写json /// /// /// /// public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (value == null) writer.WriteValue(value); else writer.WriteValue(value + ""); } } }