encoder不转义html

This commit is contained in:
白茶清欢 2023-09-01 18:32:03 +08:00
parent 25bed80472
commit 5f80644a31

View File

@ -71,7 +71,9 @@ func (oj *ownJSON) UnmarshalWithNumberForString(input string, receiver interface
// Date : 21:56 2023/7/22 // Date : 21:56 2023/7/22
func (oj *ownJSON) MarshalForByte(input interface{}) []byte { func (oj *ownJSON) MarshalForByte(input interface{}) []byte {
buffer := bytes.NewBuffer([]byte{}) buffer := bytes.NewBuffer([]byte{})
_ = json.NewEncoder(buffer).Encode(input) encoder := json.NewEncoder(buffer)
encoder.SetEscapeHTML(true)
_ = encoder.Encode(input)
return buffer.Bytes() return buffer.Bytes()
} }
@ -81,9 +83,7 @@ func (oj *ownJSON) MarshalForByte(input interface{}) []byte {
// //
// Date : 21:56 2023/7/22 // Date : 21:56 2023/7/22
func (oj *ownJSON) MarshalForString(input interface{}) string { func (oj *ownJSON) MarshalForString(input interface{}) string {
buffer := bytes.NewBuffer([]byte{}) return string(oj.MarshalForByte(input))
_ = json.NewEncoder(buffer).Encode(input)
return buffer.String()
} }
// ConsoleOutput ... // ConsoleOutput ...