简体   繁体   English

如何从ASP.NET WebApi中的对象中排除某些属性

[英]How to exclude some property from object in ASP.NET WebApi

如果我有一个从WebApi返回的对象,是否可以将其中一个属性标记为隐藏?

You can use: 您可以使用:

[JsonIgnore]
[XmlIgnore]

These will hide your property from both kinds of serialization. 这些将隐藏您的属性两种序列化。 I have always tried to mix both in a single class but JSonIgnoreAtrribute is a sealed class and does not leave us with a seamless integration option. 我一直试图将它们混合在一个类中,但JSonIgnoreAtrribute是一个密封类,并没有给我们带来无缝集成选项。

So the straight forward way is to add both attributes on your ignorable property. 因此,直接的方法是在可忽略的属性上添加两个属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM