我正在尝试将 go 结构转换为 JSON。我以为我知道该怎么做,但我对这个程序的输出感到困惑。我错过了什么?
package main
import "fmt"
import "encoding/json"
type Zoo struct {
name string
animals []Animal
}
type Animal struct {
species string
says string
}
func main() {
zoo := Zoo{"Magical Mystery Zoo",
[]Animal {
{ "Cow", "Moo"},
{ "Cat", "Meow"},
{ "Fox", "???"},
},
}
zooJson, err := json.Marshal(zoo)
if (err != nil) {
fmt.Println(err)
}
fmt.Println(zoo)
fmt.Println(zooJson)
}
输出:
{Magical Mystery Zoo [{Cow Moo} {Cat Meow} {Fox ???}]}
[123 125]
预期输出(类似的东西):
{Magical Mystery Zoo [{Cow Moo} {Cat Meow} {Fox ???}]}
{
"name" : "Magical Mystery Zoo",
"animals" : [{
"name" : "Cow",
"says" : "moo"
}, {
"name" : "Cat",
"says" : "Meow"
}, {
"name" : "Fox",
"says" : "???"
}
]
}
哪里[123 125]来的?
DIEA
温温酱
相关分类