旧版asp的json序列化程序设置.net核心应用程序是通过增加AddMvc().AddJsonOptions()来设置的,但我没有在asp.net core 3中使用AddMvc().那么如何设置全局json序列化设置呢?

推荐答案

AddMvc returns an IMvcBuilder implementation, which has a corresponding AddJsonOptions extension method. The new-style methods AddControllers, AddControllersWithViews, and AddRazorPages also return an IMvcBuilder implementation. Chain with these in the same way you would chain with AddMvc:

services.AddControllers()
    .AddJsonOptions(options =>
    {
        // ...
    });

Note that options here is no longer for Json.NET, but for the newer System.Text.Json APIs. If you still want to use Json.NET, see tymtam's answer

Json相关问答推荐

如何使用PlayWriter循环访问JSON对象

当有2个嵌套数组时展平复杂的JSON

集成wix.comstore API|变音符号问题

使用 jolt 变换压平具有公共列 JSON 的复杂嵌套

将JSON行转换为TSV格式, for each 数组项生成单独的行

使用 jq 工具将文本从 txt 文件转换为 json

如何使用 Google 表格应用程序脚本将 JSON 中的多个字段提取到 Google 表格中

JOLT JSON 将值从一对多转换为一对一

如何将动态复杂 json 解析为dart 对象或模型

使用 json_query 过滤嵌套列表中的元素

如何解决名为 null 的map值

哪个更好:Json 或 XML (PHP)

如何从 mysql 数据库构建 JSON 数组

苗条的 JSON 输出

如何向(JSON)对象的原型添加方法?

Jackson:忽略 Json 配置值

在 Java 中比较两个 JSON 文件的最佳方法

如何使用 Javascript 将数据写入 JSON 文件

春天:返回@ResponseBodyResponseEntity>

杰克逊自动将 Joda DateTime 格式化为 ISO 8601 格式