最佳答案
我使用Json。网将一个类序列化为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; }
}
我想添加一个JsonIgnore()属性Test2List属性只有当Test2List是null。如果它不是空的,那么我想包括它在我的json。