Skip to content

Using the standard library JSON to serialize structures, strange spaces may appear when Chinese characters appear. #71637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LuanShiLiuNian opened this issue Feb 10, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@LuanShiLiuNian
Copy link

Go version

go version go1.23.5 windows/386

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=386
set GOBIN=
set GOCACHE=C:\Users\XiaoZhang\AppData\Local\go-build
set GOENV=C:\Users\XiaoZhang\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=386
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=F:\DevelopmentTools\goPath\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=F:\DevelopmentTools\goPath\
set GOPRIVATE=
set GOPROXY=https://goproxy.cn
set GOROOT=F:\DevelopmentTools\golang
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=F:\DevelopmentTools\golang\pkg\tool\windows_386
set GOVCS=
set GOVERSION=go1.23.5
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\XiaoZhang\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GO386=sse2
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m32 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\XIAOZH~1\AppData\Local\Temp\go-build2387523124=/tmp/go-build -gno-record-gcc-switches

What did you do?

type ApiRequest struct {
Model string json:"model"
Messages []Message json:"messages"
Temperature float64 json:"temperature"
ResponseFormat struct {
Type string json:"type"
} json:"response_format"
}

type Message struct {
Role string json:"role:"
Content string json:"content"
}

apiReq := &ApiRequest{
	Model: "deepseek-ai/DeepSeek-R1-Distill-Llama-8B",
	Messages: []Message{
		{
			Role:    "user",
			Content: "你好,你在干什么。",
		},
	},
	Temperature: 1.3,
	ResponseFormat: struct {
		Type string `json:"type"`
	}{
		Type: "text",
	},
}

marshal, err := json.Marshal(apiReq)
if err != nil {
	return "", err
}
println(string(marshal))

What did you see happen?

console out :
{"model":"deepseek-ai/DeepSeek-R1-Distill-Llama-8B","messages":[{"role:":"user","content":"你好,你在干什么。"}],"temperature":1.3,"r esponse_format":{"type":"text"}}
Image

What did you expect to see?

Better handling of Chinese

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 10, 2025
@seankhliao
Copy link
Member

that like more like a display issue with your terminal, go's output looks fine.
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

3 participants