How can we hide a property in WebAPI?

后端 未结 5 2079
春和景丽
春和景丽 2020-12-14 10:04

I have a model say under

public class Device
{        
        public int DeviceId { get; set; }
        public string DeviceTokenIds { get; set; }
        p         


        
5条回答
  •  死守一世寂寞
    2020-12-14 10:37

    If you are using Newtonsoft.Json

    you can hide the properties like this:

    public class Product
    {
        [JsonIgnore]
        public string internalID { get; set; };
        public string sku { get; set; };
        public string productName { get; set; };
    }
    

    and your serialized response will not include the internalID property.

提交回复
热议问题