go
go copied to clipboard
Cannot unmarshal struct when key is also ASCII escaped
version: v1.1.10
code:
package main
import (
"encoding/json"
"fmt"
jsoniter "github.com/json-iterator/go"
)
type obj struct {
Msg string `json:"消息"`
}
func main() {
jsonit := jsoniter.ConfigCompatibleWithStandardLibrary
// \u6D88\u606F are escaped charecters for Chinese word "消息"
b := []byte(`{"\u6D88\u606F":"\u6D88\u606F"}`)
o := obj{}
json.Unmarshal(b, &o)
fmt.Printf("got json object: %+v\n", o)
o = obj{}
jsonit.Unmarshal(b, &o)
fmt.Printf("got jsonit object: %+v\n", o)
}
Go output:
got json object: {Msg:消息}
got jsonit object: {Msg:}
But expected:
got json object: {Msg:消息}
got jsonit object: {Msg:消息}
Similar issue exists on https://github.com/goccy/go-json/issues/234 go-json package as well
However, official "encoding/json" works well