在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
遇到的json异常: 处理方法:
修改为:
查阅资料: 里面说: ASP.NET Core 3.0 now uses System.Text.Json by default for JSON serialization:
To add Json.NET to ASP.NET Core 3.0, see Add Newtonsoft.Json-based JSON format support. 在这篇文章里查找到解决办法 简单翻译如下: 作为ASP.NET Core 3.0的一部分,该团队默认情况下不再包括Json.NET。您可以在有关对Microsoft.AspNetCore.App进行重大更改的公告中了解有关此内容的更多信息。 Instead of Json.NET, ASP.NET Core 3.0 and .NET Core 3.0 include a different JSON API that focuses a bit more on performance. You can learn about that more in the announcement about “The future of JSON in .NET Core 3.0”. The new templates for ASP.NET Core will no longer bundle with Json.NET but you can easily reconfigure the project to use it instead of the new JSON library. This is important for both compatibility with older projects and also because the new library is not supposed to be a full replacement, so you won't see the full feature set there. ASP.NET Core的新模板将不再与Json.NET捆绑在一起,但是您可以轻松地重新配置项目以使用它而不是新的JSON库。这对于与较早项目的兼容性以及对新库都不应完全替代都非常重要,因此您在此处看不到全部功能。 In order to reconfigure your ASP.NET Core 3.0 project with Json.NET, you will need to add a NuGet reference to Microsoft.AspNetCore.Mvc.NewtonsoftJson, which is the package that includes all the necessary bits. Then, in the Startup’s ConfigureServices, you will need to configure MVC like this: 为了使用Json.NET重新配置ASP.NET Core 3.0项目,您将需要添加对Microsoft.AspNetCore.Mvc.NewtonsoftJson的NuGet引用,该包包含所有必要的位。然后,您需要在启动公司的ConfigureServices中配置MVC,如下所示:
This sets up MVC controllers and configures it to use Json.NET instead of that new API. Instead of controllers, you can also use a different MVC overload (e.g. for controllers with views, or Razor pages). 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. 这将设置MVC控制器并将其配置为使用Json.NET而不是该新API。除了控制器以外,您还可以使用其他MVC重载(例如,具有视图或Razor页面的控制器)。该AddNewtonsoftJson方法有一个重载,使您可以像在ASP.NET Core 2.x中使用AddJsonOptions一样配置Json.NET选项。
看来要抽空对比一下3.1的system.text.json和newton.json认证更好用了。 |
请发表评论