From a094e59ffc17fd19ce0d6a3894e4d5d1afd82914 Mon Sep 17 00:00:00 2001 From: haoliang <821644@qq.com> Date: Wed, 29 Apr 2026 00:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DAPI=E8=BF=94=E5=9B=9EPascalCa?= =?UTF-8?q?se=E5=AF=BC=E8=87=B4=E5=89=8D=E7=AB=AF=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0message=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - WebApiConfig: 添加CamelCasePropertyNamesContractResolver - 后端JSON输出从 Code/Message/Data 改为 code/message/data - 前端拦截器 res.message 现在能正确取到后端错误信息 --- src/CncWebApi/App_Start/WebApiConfig.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CncWebApi/App_Start/WebApiConfig.cs b/src/CncWebApi/App_Start/WebApiConfig.cs index 2672acc..d46021d 100644 --- a/src/CncWebApi/App_Start/WebApiConfig.cs +++ b/src/CncWebApi/App_Start/WebApiConfig.cs @@ -2,6 +2,7 @@ using System.Web.Http; using System.Web.Http.Cors; using CncWebApi.Filters; using CncWebApi.Infrastructure; +using Newtonsoft.Json.Serialization; namespace CncWebApi.App_Start { @@ -29,7 +30,9 @@ namespace CncWebApi.App_Start // 全局异常过滤器 config.Filters.Add(new GlobalExceptionFilter()); - // 统一JSON序列化设置 + // 统一JSON序列化设置:camelCase输出(Code→code, Message→message, Data→data) + config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = + new CamelCasePropertyNamesContractResolver(); config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; config.Formatters.JsonFormatter.SerializerSettings.DateFormatString =