diff --git a/Communications/SimApiBaseResponse.cs b/Communications/SimApiBaseResponse.cs
index 2c7a01a..ea0ff66 100644
--- a/Communications/SimApiBaseResponse.cs
+++ b/Communications/SimApiBaseResponse.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
+using SimApi.Helpers;
namespace SimApi.Communications;
@@ -36,15 +37,7 @@ public class SimApiBaseResponse(int code = 200, string message = "成功")
///
public override string ToString()
{
- return JsonSerializer.Serialize(this, new JsonSerializerOptions
- {
- IgnoreReadOnlyProperties = true,
- PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
- Converters =
- {
- new JsonStringEnumConverter()
- }
- });
+ return SimApiUtil.Json(this);
}
}
diff --git a/Helpers/SimApiResponseFilter.cs b/Helpers/SimApiResponseFilter.cs
new file mode 100644
index 0000000..2737b75
--- /dev/null
+++ b/Helpers/SimApiResponseFilter.cs
@@ -0,0 +1,27 @@
+using System;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Filters;
+using SimApi.Communications;
+
+namespace SimApi.Helpers;
+
+public class SimApiResponseFilter : IResultFilter
+{
+ public void OnResultExecuting(ResultExecutingContext context)
+ {
+ context.Result = context.Result switch
+ {
+ // 检查结果是否为 null
+ null => new OkObjectResult(new SimApiBaseResponse()),
+ ObjectResult { Value: SimApiBaseResponse simApiBaseResponse } =>
+ new OkObjectResult(simApiBaseResponse),
+ ObjectResult objectResult => new OkObjectResult(new SimApiBaseResponse