From 25bed804727ab0c2c83da37a0867e40e7bcda5e0 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:21:38 +0800 Subject: [PATCH] =?UTF-8?q?json=20=E5=BA=8F=E5=88=97=E5=8C=96=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E5=AD=97=E7=AC=A6=E4=B8=8D=E8=BD=AC=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/json.go b/json.go index 284cbf6..52cb400 100644 --- a/json.go +++ b/json.go @@ -70,8 +70,9 @@ func (oj *ownJSON) UnmarshalWithNumberForString(input string, receiver interface // // Date : 21:56 2023/7/22 func (oj *ownJSON) MarshalForByte(input interface{}) []byte { - byteData, _ := json.Marshal(input) - return byteData + buffer := bytes.NewBuffer([]byte{}) + _ = json.NewEncoder(buffer).Encode(input) + return buffer.Bytes() } // MarshalForString 序列化并返回字符串 @@ -80,8 +81,9 @@ func (oj *ownJSON) MarshalForByte(input interface{}) []byte { // // Date : 21:56 2023/7/22 func (oj *ownJSON) MarshalForString(input interface{}) string { - byteData := oj.MarshalForByte(input) - return string(byteData) + buffer := bytes.NewBuffer([]byte{}) + _ = json.NewEncoder(buffer).Encode(input) + return buffer.String() } // ConsoleOutput ...