使用.net core3和新的JSON API序列化IList属性

时间:2019-09-30 06:13:17

标签: json .net-core-3.0

.netcore 3.0引入了新的快速json API。我有要序列化列表属性的对象:

public class X {
   ...
   IList<Y> SomeListProperty = new List<Y>();
}

这似乎不起作用,只是忽略列表属性。我尝试使用 MaxDepth 属性对其进行配置,但无法正常工作。 https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions?view=netcore-3.0

services.AddJsonOptions(options => options.JsonSerializerOptions.MaxDepth= 4);

它与newtonsoft一起使用。尚不支持此功能吗?

1 个答案:

答案 0 :(得分:0)

我发现了问题。名称空间 System.Text.Json.Serialization 中的新序列化器将不会序列化列表中的字段。 Newtonsoft序列化程序可以。我忘记了塞特和吸气剂。 错误:

C:\Users

右:

public class X {
   ...
   IList<Y> SomeListProperty = new List<Y>();
}