可能因为在 .net core 3.1 后,序列化组件已经是:System.Text.Json,序列化的默认行为有改变。

 

解决方案1:更换 JSON 组件(https://q.cnblogs.com/q/114831/

添加 Microsoft.AspNetCore.Mvc.NewtonsoftJson 包引用,并且在 ConfigureServices 中添加 AddNewtonsoftJson()

 

解决方案2:配置 JSON 选项(https://q.cnblogs.com/q/115234/

在 Startup 中配置:

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers().AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
    });
}

即可,如果需要更宽泛的转换,可将 Encoder 更换为:JavaScriptEncoder.UnsafeRelaxedJsonEscaping

相关文章:

  • 2021-07-27
  • 2021-04-23
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
猜你喜欢
  • 2022-01-24
  • 2022-01-23
  • 2022-02-18
  • 2021-06-13
  • 2021-08-25
  • 2022-02-10
  • 2022-12-23
相关资源
相似解决方案