public class TimeSpanConverter : JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof (TimeSpan); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteStartObject(); writer.WritePropertyName( " $type " ); writer.WriteValue(value.GetType().FullName); writer.WritePropertyName( " $value " ); writer.WriteValue(value); writer.WriteEndObject(); } public override object ReadJson(JsonReader reader, Type type, object value, JsonSerializer serializer) { return value; } }
stackoverflow在找一下