C# Json.Net-如何仅在类型匹配时反序列化

C# Json.Net-如何仅在类型匹配时反序列化,c#,.net,json,json.net,C#,.net,Json,Json.net,我有一门课是这样的: public class Event { [JsonProperty(PropertyName = "_id")] public string Id { get; set; } [JsonProperty(PropertyName = "status"] public string Status { get; set; } } [ { "_id": 4,

我有一门课是这样的:

public class Event
{
            [JsonProperty(PropertyName = "_id")]
            public string Id { get; set; }
            [JsonProperty(PropertyName = "status"]
            public string Status { get; set; }
}
[
    {
        "_id": 4,
        "status": "started"
    },
    {
        "_id": 117841261,
        "status": {
            "_statusid": 1,
            "date": "01.01.2015"
        }
    }
]
public class Event
{
            [JsonProperty(PropertyName = "_id")]
            public string Id { get; set; }
            [JsonProperty(PropertyName = "status"]
            public dynamic Status { get; set; }
}
我收到的JSON如下所示:

public class Event
{
            [JsonProperty(PropertyName = "_id")]
            public string Id { get; set; }
            [JsonProperty(PropertyName = "status"]
            public string Status { get; set; }
}
[
    {
        "_id": 4,
        "status": "started"
    },
    {
        "_id": 117841261,
        "status": {
            "_statusid": 1,
            "date": "01.01.2015"
        }
    }
]
public class Event
{
            [JsonProperty(PropertyName = "_id")]
            public string Id { get; set; }
            [JsonProperty(PropertyName = "status"]
            public dynamic Status { get; set; }
}
请注意:在第一个对象中,状态字段是一个字符串。在第二个对象中,它是一个对象。在我的对象中,它是一个字符串属性。每当status字段是字符串时,我都要解析它。当它是第二个对象时,我可以跳过它


我已尝试更改
JsonProperty
属性中的
defaultValueHanding
选项,但没有任何帮助。有没有办法做到这一点?

我已经解决了将属性类型更改为动态的问题。所以它每次都是反序列化的,没有问题,我只是在需要的时候才使用它

现在,我的模型如下所示:

public class Event
{
            [JsonProperty(PropertyName = "_id")]
            public string Id { get; set; }
            [JsonProperty(PropertyName = "status"]
            public string Status { get; set; }
}
[
    {
        "_id": 4,
        "status": "started"
    },
    {
        "_id": 117841261,
        "status": {
            "_statusid": 1,
            "date": "01.01.2015"
        }
    }
]
public class Event
{
            [JsonProperty(PropertyName = "_id")]
            public string Id { get; set; }
            [JsonProperty(PropertyName = "status"]
            public dynamic Status { get; set; }
}
正如Brian Rogers指出的,可以在这里找到自定义转换器:


在第二个对象中,status是一个对象,而不是数组。@X.L.Ant。谢谢。这个问题不是重复标记的问题,因为它不是关于模式验证的问题。然而,我认为这是一个复制品