.net核心3 AddJsonOptions中没有ReferenceLoopHandling [英] .net core 3 not having ReferenceLoopHandling in AddJsonOptions
问题描述
我的csproject文件指示:<TargetFramework>netcoreapp3.0</TargetFramework>
My csproject file is indicating: <TargetFramework>netcoreapp3.0</TargetFramework>
在我的启动即时消息中,使用followinhg:
In my startup im using the followinhg:
services.AddMvc(x => x.Filters.AddService<TransactionFilter>())
.AddJsonOptions(options => options.JsonSerializerOptions... )
但是,options.JsonSerializerOptions
内部没有ReferenceLoopHandling.
But, ReferenceLoopHandling is not available inside options.JsonSerializerOptions
.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentNHibernate" Version="2.1.2" />
<PackageReference Include="FullContact.Contacts.API" Version="1.0.3" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.5.0" />
<PackageReference Include="MySql.Data" Version="8.0.17" />
<PackageReference Include="piplclient" Version="5.0.9" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.5.0" />
</ItemGroup>
</Project>
推荐答案
作为 Json.NET 已从ASP.NET Core共享框架中删除.如果您的应用程序使用Newtonsoft.Json特定的功能(例如JsonPatch或转换器)或者
As part of the work to improve the ASP.NET Core shared framework, Json.NET has been removed from the ASP.NET Core shared framework. Your app may require this reference if it uses Newtonsoft.Json-specific feature such as JsonPatch or converters or if it formats Newtonsoft.Json-specific types.
要在ASP.NET Core 3.0项目中使用Json.NET:
To use Json.NET in an ASP.NET Core 3.0 project:
添加对 Microsoft.AspNetCore.Mvc.NewtonsoftJson 的程序包引用
更新Startup.ConfigureServices
以调用AddNewtonsoftJson
.
services.AddMvc()
.AddNewtonsoftJson();
这将设置MVC并将其配置为使用Json.NET而不是该新API.而且,该AddNewtonsoftJson方法具有重载功能,使您可以像在ASP.NET Core 2.x中使用AddJsonOptions一样配置Json.NET选项.
This sets up MVC and configures it to use Json.NET instead of that new API. And that AddNewtonsoftJson method has an overload that allows you to configure the Json.NET options like you were used to with AddJsonOptions in ASP.NET Core 2.x.
services.AddMvc()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings = new JsonSerializerSettings() { … };
});
参考:
https://stackoverflow.com/a/55666898/10201850
这篇关于.net核心3 AddJsonOptions中没有ReferenceLoopHandling的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!