小编Fab*_*ano的帖子

使用新的“System.Text.Json”类(Asp.net core 3.0 preview 8)序列化 System.Data.DataTable 时出现异常

我正在 asp.net core 3.0 preview 8 中编写一个 rest api,我试图使用新的“System.Text.Json”类序列化 System.Data.DataTable,但在 Serialize 方法中我收到异常:

不支持“System.Data.DataTable.ChildRelations”上的集合类型“System.Data.DataRelationCollection”。

使用 newtonsoft json 序列化程序可以很好地进行相同的序列化。

重现问题的示例代码:

var dt = new System.Data.DataTable("test");
dt.Columns.Add("Column1");
var ser=System.Text.Json.JsonSerializer.Serialize(dt);
Run Code Online (Sandbox Code Playgroud)

详细异常:

System.NotSupportedException HResult=0x80131515 Message=不支持“System.Data.DataTable.ChildRelations”上的集合类型“System.Data.DataRelationCollection”。Source=System.Text.Json StackTrace: 在 System.Text.Json.JsonClassInfo.GetElementType(Type propertyType, Type parentType, MemberInfo memberInfo, JsonSerializerOptions options) at System.Text.Json.JsonClassInfo.CreateProperty(Type DeclarationPropertyType, Type runtimePropertyType, Type在 System.Text.Json.JsonClassInfo.AddProperty(Type propertyType, PropertyInfo propertyInfo, Type classType, JsonSerializerOptions options) 在 System.Text.Json.JsonClassInfo..ctor(Type type, JsonSerializerOptions)选项)在 System.Text.Json。

你能帮忙吗?

谢谢你。

asp.net json system.text.json

3
推荐指数
1
解决办法
2034
查看次数

标签 统计

asp.net ×1

json ×1

system.text.json ×1