我有一个返回的json字符串:
{“ expires_in”:300}
我定义了一个类:
class Test
{
public DateTime ExpirationDate {get;set;}
}
现在我想反序列化到该对象中,但想将300转换为DateTime.Now.AddSeconds(300),所以我这样做了:
JsonConvert.DeserializeObject<Test>("{ \"expires_in\": 300 }");
所以我尝试了:
class Test
{
[JsonProperty("expires_in", ItemConverterType=typeof(TestConverter))]
public DateTime ExpirationDate {get;set;}
}
但是它似乎从未进入转换器。我想念什么吗?
转换器刚被存根:
class TestConvert : JsonConverter
{
public override bool CanConvert(Type objectType)
{
throw new NotImplementedException();
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}