encoding/json: trouble with Marshal of Chinese word on Windows #3005
Labels
Comments
Hi hongruiqi/Russ, First, the len(bs) is 49, and the file is saved as utf-8 file. I attached the source file and the printscreen img, it shows that there missed a double quote just before `,"data"`, pls check it, thanks. Sorry for late reply! Attachments:
|
Thanks for the test case. I think this is working correctly and that your terminal is getting confused by the full-width exclamation mark followed by an ASCII quotation mark. Note that in the screen shot it says ? where the full-width exclamation mark and " should be. $ cat x.go package main import ( "encoding/json" "fmt" "strconv" ) type Resp struct { Errno uint Error string Data interface{} } func main() { resp := Resp{ Errno: 0, Error: "\u9519\u8bef\u6d4b\u8bd5\uff01", //some chinese word. Data: nil, } bs, err := json.Marshal(resp) if err != nil { panic(err) } fmt.Printf("JSON: %s\n", bs) fmt.Printf("Error: %q\n", resp.Error) fmt.Printf("%q\n", bs) fmt.Printf("\n") fmt.Printf("Error: %s\n", strconv.QuoteToASCII(resp.Error)) fmt.Printf("%s\n", strconv.QuoteToASCII(string(bs))) } $ go run x.go JSON: {"Errno":0,"Error":"错误测试!","Data":null} Error: "错误测试!" "{\"Errno\":0,\"Error\":\"错误测试!\",\"Data\":null}" Error: "\u9519\u8bef\u6d4b\u8bd5\uff01" "{\"Errno\":0,\"Error\":\"\u9519\u8bef\u6d4b\u8bd5\uff01\",\"Data\":null}" $ |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by yunge.fu:
The text was updated successfully, but these errors were encountered: