如何在序列化中忽略属性,但在C#中使用json.net进行反序列化。
例:
public class Foo
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("contentType")]
public object ContentType { get; set; }
[JsonProperty("content")]
public object Content { get; set; }
[JsonIgnore]
public Relationship RelationshipContent { get; set; }
[JsonIgnore]
public Domains DomainContent { get; set; }
}
在上面的代码中,我需要根据PartType属性值的值将“内容”反序列化为属性“ RelationshipContent”和“ DomainContent”。
您能帮我使用Newtonsoft.Json在C#中做到这一点吗?
您能否提供一种“设置”Content
并将数据处理到正确位置的方法。
public class Foo
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("contentType")]
public object ContentType { get; set; }
[JsonProperty("content")]
public object Content { get; set {
//do something here with `value` e.g.
RelationshipContent = value; //change as required
DomainContent = value; //change as required
}
}
[JsonIgnore]
public Relationship RelationshipContent { get; set; }
[JsonIgnore]
public Domains DomainContent { get; set; }
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句