typora/note/Go/json转义HTML.md

11 lines
205 B
Markdown
Raw Permalink Normal View History

2024-12-11 21:48:55 -05:00
### 1、NewEncoder
```go
writer := bytes.Buffer{}
encoder := json.NewEncoder(&writer)
encoder.SetEscapeHTML(false)
encoder.Encode(struct{ Name string }{Name: "1111"})
jsonStr := writer.String()
```