Json.net 同过 JsonConverter 调整导出值(未完成)

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在找一下

posted on 2014-08-19 16:24  聪明的大熊  阅读(268)  评论(0编辑  收藏  举报