我有一个名为的 JSON 文件example.json,如下所示:


{

    "name": "example",

    "type": "record"

}

我还有一个将上述内容表示为“字符串”的变量:


const example = `{

    "name": "example",

    "type": "record",

}`

我试图理解为什么将 JSON 文件的内容读入字节与读取变量的内容example不同。我的代码如下:


    bytesJSON, err := ioutil.ReadFile("example.json")

    if err != nil {

        fmt.Println(err)

    }


    bytesVar, err := json.Marshal(example)

    if err != nil {

        fmt.Println(err)

    }

两者都是 type []uint8,但看起来非常不同。关于为什么的任何想法?以及如何确保它们始终相同?




bytesJSON好像:


[123 10 32 32 32 32 34 110 97 109 101 34 58 32 34 101 120 97 109 112 108 101 34 44 10 32 32 32 32 34 116 121 112 101 34 58 32 34 114 101 99 111 114 100 34 10 125]


bytesVar好像:


[34 112 117 98 115 117 98 95 101 120 97 109 112 108 101 95 116 111 112 105 99 34]


当打印到stdout.