From 5f80644a31a527785e9ace005b538c5ca7f29d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 1 Sep 2023 18:32:03 +0800 Subject: [PATCH] =?UTF-8?q?encoder=E4=B8=8D=E8=BD=AC=E4=B9=89html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/json.go b/json.go index 52cb400..ab66a74 100644 --- a/json.go +++ b/json.go @@ -71,7 +71,9 @@ func (oj *ownJSON) UnmarshalWithNumberForString(input string, receiver interface // Date : 21:56 2023/7/22 func (oj *ownJSON) MarshalForByte(input interface{}) []byte { buffer := bytes.NewBuffer([]byte{}) - _ = json.NewEncoder(buffer).Encode(input) + encoder := json.NewEncoder(buffer) + encoder.SetEscapeHTML(true) + _ = encoder.Encode(input) return buffer.Bytes() } @@ -81,9 +83,7 @@ func (oj *ownJSON) MarshalForByte(input interface{}) []byte { // // Date : 21:56 2023/7/22 func (oj *ownJSON) MarshalForString(input interface{}) string { - buffer := bytes.NewBuffer([]byte{}) - _ = json.NewEncoder(buffer).Encode(input) - return buffer.String() + return string(oj.MarshalForByte(input)) } // ConsoleOutput ...