json 序列化特殊字符不转义

This commit is contained in:
白茶清欢 2023-09-01 18:21:38 +08:00
parent 5c584bcb76
commit 25bed80472

10
json.go
View File

@ -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 ...