[英] How to exclude property from Json Serialization
我有一个我序列化的DTO类
Json.Serialize(MyClass)
我怎么能排除它public的财产呢?
(It has to be public, as I use it in my code somewhere else)
我有一个我序列化的DTO类
Json.Serialize(MyClass)
我怎么能排除它public的财产呢?
(It has to be public, as I use it in my code somewhere else)
If you are using Json.Net attribute [JsonIgnore]
will simply ignore the field/property while serializing or deserialising.
public class Car
{
// included in JSON
public string Model { get; set; }
public DateTime Year { get; set; }
public List<string> Features { get; set; }
// ignored
[JsonIgnore]
public DateTime LastModified { get; set; }
}
或者可以使用DataContract和DataMember属性有选择地序列化/反序列化属性/字段.
[DataContract]
public class Computer
{
// included in JSON
[DataMember]
public string Name { get; set; }
[DataMember]
public decimal SalePrice { get; set; }
// ignored
public string Manufacture { get; set; }
public int StockCount { get; set; }
public decimal WholeSalePrice { get; set; }
public DateTime NextShipmentDate { get; set; }
}
Refer http://james.newtonking.com/archive/2009/10/23/efficient-json-with-json-net-reducing-serialized-json-size for more details
在 Perl Mojolicious 中呈现 JSON 时防止转义字符
PowerShell - JSON/PsCustomObject - 为什么我的数组被扁平化为一个对象?
PowerShell - 如何迭代 PSCustomObject 嵌套对象?
Golang / Go - 如果结构没有字段,如何将其编组为空?
type 'List
如何从 Python 中的文件/流中懒惰地读取多个 JSON 值?
处理响应 - SyntaxError:使用模式时输入意外结束:'no-cors'
TypeError:JSON 对象必须是 str,而不是 'bytes'
使用 Retrofit & Gson 解析 JSON 数组响应
React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0