小编Jos*_*cia的帖子

CamelCase 无法在 net core 6 Web api 中工作

我已将 Web api 应用程序从 net core 5 迁移到 6,并通过 System.Text.Json 更改了 NewtonSoft 序列化程序。在我的 Startup.cs 中,我使用以下代码配置了 Json 序列化:

services.AddControllers(config =>
{
    config.RespectBrowserAcceptHeader = true;
    config.ReturnHttpNotAcceptable = true;
})
.AddJsonOptions(options =>
{
    options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
    options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
    options.JsonSerializerOptions.WriteIndented = true;
})
.AddXmlDataContractSerializerFormatters();
Run Code Online (Sandbox Code Playgroud)

该代码仅部分有效。WriteIndented 工作正常(请参见下面的屏幕截图),但我无法让驼峰式工作。

在此输入图像描述

有什么建议么?问候

c# asp.net-core-webapi system.text.json asp.net-core-6.0

7
推荐指数
1
解决办法
9893
查看次数