From 1c4fb0616341c476e9da94385da7a5560b323857 Mon Sep 17 00:00:00 2001 From: xRain Date: Mon, 16 May 2022 11:26:42 +0800 Subject: [PATCH] add json util --- Helpers/SimApiUtil.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Helpers/SimApiUtil.cs b/Helpers/SimApiUtil.cs index ee035f7..5045c56 100644 --- a/Helpers/SimApiUtil.cs +++ b/Helpers/SimApiUtil.cs @@ -1,6 +1,9 @@ using System.Security.Cryptography; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Json; using System.Text.RegularExpressions; +using System.Text.Unicode; namespace SimApi.Helpers { @@ -36,5 +39,18 @@ namespace SimApi.Helpers return strbul.ToString(); } + + /// + /// 将对象序列化成JSON (控制台输出中文不会被编码) + /// + /// + /// + public static string Json(object obj) + { + return JsonSerializer.Serialize(obj, new JsonSerializerOptions + { + Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) + }); + } } } \ No newline at end of file