【发布时间】:2011-09-24 08:57:22
【问题描述】:
我正在使用Json.NET 将一个类序列化为 JSON。
我有这样的课程:
class Test1
{
[JsonProperty("id")]
public string ID { get; set; }
[JsonProperty("label")]
public string Label { get; set; }
[JsonProperty("url")]
public string URL { get; set; }
[JsonProperty("item")]
public List<Test2> Test2List { get; set; }
}
仅当Test2List 为null 时,我才想将JsonIgnore() 属性添加到Test2List 属性。如果它不为空,那么我想将它包含在我的 json 中。
【问题讨论】: