序列化程序不起作用

序列化程序不起作用

本文介绍了升级到 3.6.2 后 JSON 序列化程序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 ASP.NET Boilerplate 用于我的一个应用程序.该应用程序在 3.5.0 版本的 Abp 上,模板是带有 MVC 的 ASP.NET Core.我最近将它升级到 3.6.2 升级很好,但是当我运行它时,所有 AJAX 调用现在都以 CamelCase 形式返回 JSON 数据,以前它是在 PascalCase 中.我正在使用 DefaultContractResolver 进行 JSON 配置

I'm using ASP.NET Boilerplate for one of my application. The application was on 3.5.0 version of Abp and the template was ASP.NET Core with MVC. I recently upgraded it to 3.6.2 the upgrade was fine but when I run it all AJAX calls are returning JSON data in CamelCase now, previously it was in PascalCase. I'm using DefaultContractResolver for JSON configuration

我尝试了 Google 和 StackOverflow 中可用的所有内容,但没有成功.我下载了最新的 ABP 模板并在那里添加了配置,但它在那里也不起作用.似乎序列化程序设置不适用.

I tried everything that was available in Google and StackOverflow, but no luck. I downloaded the latest ABP template and added configuration there as well but it is not working there as well. Seems like serializer settings are not applying.

有人知道怎么解决吗?

我的代码配置是:

services.AddMvc().AddJsonOptions(x =>
            x.SerializerSettings.ContractResolver = new DefaultContractResolver());

如果您需要更多信息,请告诉我.

Please let me know if you need more information.

提前致谢.

推荐答案

Startup.cs中设置> ConfigureServices()方法

services.PostConfigure<MvcJsonOptions>(options =>
{
    options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});

这篇关于升级到 3.6.2 后 JSON 序列化程序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 09:38