我正在使用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; }
}
Run Code Online (Sandbox Code Playgroud)
我想将添加JsonIgnore()属性,Test2List只有当财产Test2List是null.如果它不为null,那么我想将它包含在我的json中.