且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有与JsonIgnore相反的东西?

更新时间:2023-11-28 23:12:58

是的.当您用[JsonObjectAttribute]标记类并传递MemberSerialization.OptIn参数时,成员序列化选择加入.然后用[JsonProperty]标记您的成员以包括它们以进行序列化.

Yes there is. When you mark your class with [JsonObjectAttribute] and pass the MemberSerialization.OptIn parameter, member serialization is opt-in. Then mark your members with [JsonProperty] to include them for serialization.

[JsonObject(MemberSerialization.OptIn)]
public class Person
{
    [JsonProperty]
    public string Name { get; set; }

    // not serialized because mode is opt-in
    public string Department { get; set; }
}