golang之处理unicode
import (
"fmt"
"strconv"
)
func main() {
// 中文转换unicode
s1 := strconv.QuoteToASCII("彬彬")
// 转换后的
fmt.Printf("%#v\n",s1) // "\"\\u5f6c\\u5f6c\""
// unicode转换中文
fmt.Println(strconv.Unquote(s1)) // 彬彬 <nil>
// unicode转换中文需要的格式 “内容” ,*注意要传双引号,*外部用来推导类型
s2 := `"\u63a8\u9001\u6210\u529f"`
fmt.Println(strconv.Unquote(s2)) // 推送成功 <nil>
// 自行处理nil
}
文档请查
https://studygolang.com/pkgdoc
strconv


浙公网安备 33010602011771号