public class Sample
{
public List<int> List { get; set; }
public Sample()
{
this.List = new List<int>();
}
}
var options = new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
};
var result = JsonSerializer.Deserialize<Sample>("{}", options);
Debug.Assert(result.List != null);
1条答案
按热度按时间tkqqtvp11#
在类构造函数中,可以示例化集合。因此,它永远不会是
null
,除非null
在json中显式提供字符串