asp web api json 序列化后 把私有字段信息也返回了解决办法

时间:2023-03-08 17:54:05
asp web api json 序列化后 把私有字段信息也返回了解决办法

serialization returns private properties

Are your types marked as [Serializable]? Serializable means that the serializer should serialize all fields - private or public.

Try to remove Serializable or else use this line to stop the JSON formatter from recognizing the attribute:

config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver();