Home > Backend Development > C++ > ASP.NET Core 3.0: Where Did `AddJsonOptions` Go?

ASP.NET Core 3.0: Where Did `AddJsonOptions` Go?

DDD
Release: 2025-01-23 01:27:10
Original
390 people have browsed it

ASP.NET Core 3.0: Where Did `AddJsonOptions` Go?

Changes in the AddJsonOptions method in ASP.NET Core 3.0

Problem: After upgrading to ASP.NET Core 3.0, the AddJsonOptions method disappeared and reinstalling the dependencies did not solve the problem.

Answer:

Background:

ASP.NET Core 3.0 changes the default JSON serialization mechanism. Json.NET has been replaced by a new, performance-focused JSON API.

Use Json.NET:

If you require Json.NET compatibility, please follow these steps:

  1. Install the Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package.
  2. In the Startup method of the ConfigureServices class, configure MVC with the following code:
<code class="language-csharp">services.AddControllers()
    .AddNewtonsoftJson();</code>
Copy after login

Configuration options:

You can further configure Json.NET options using overloaded methods:

<code class="language-csharp">services.AddControllers()
    .AddNewtonsoftJson(options =>
    {
        options.SerializerSettings.ContractResolver = new DefaultContractResolver();
    });</code>
Copy after login

The above is the detailed content of ASP.NET Core 3.0: Where Did `AddJsonOptions` Go?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template