using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Wood.Util { public class NullableIntConverter: JsonConverter { public override int? ReadJson(JsonReader reader, Type objectType, int? existingValue, bool hasExistingValue, JsonSerializer serializer) { if ((reader.Value == null || reader.Value.ToString() == "")) return 0; return Convert.ToInt32(reader.Value); } public override void WriteJson(JsonWriter writer, int? value, JsonSerializer serializer) { writer.WriteValue(value); } } }