Ignore property defined in interface when serializing using JSON.net

前端 未结 4 966
一向
一向 2021-01-11 10:47

I have an interface with a property like this:

public interface IFoo {
    // ...

    [JsonIgnore]
    string SecretProperty { get; }

    // ...
}
<         


        
4条回答
  •  时光说笑
    2021-01-11 11:07

    You should add [DataContract] in front of the class name.

    It changes the default from including all properties, to including only explicitly marked properties. After that, add '[DataMember]' in front of each property you want to include in the JSON output.

提交回复
热议问题