ToJson方法防止中文编码

This commit is contained in:
Falcon 2025-03-06 14:37:23 +08:00
parent 7aaaacb309
commit 7350a60bb2

View File

@ -5,7 +5,9 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;
namespace Falcon.SugarApi
{
@ -142,6 +144,7 @@ namespace Falcon.SugarApi
/// <returns>转换后字符串</returns>
public static string ToJson<T>(this T obj,Action<JsonSerializerOptions>? OptionBuilder = null) {
var option = new JsonSerializerOptions();
option.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
OptionBuilder?.Invoke(option);
var ser = new JsonSerialize.JsonSerializeFactory().CreateJsonSerialize(option);
return ser.Serialize(obj);