<分区>
我想像这样在 go 中编码和取消编码递归类型:
type Dog struct {
age int
sibling *Dog
}
有什么办法可以在 golang 中做到这一点吗?我尝试使用 json.Marshal 但它不起作用。
<分区>
我想像这样在 go 中编码和取消编码递归类型:
type Dog struct {
age int
sibling *Dog
}
有什么办法可以在 golang 中做到这一点吗?我尝试使用 json.Marshal 但它不起作用。
最佳答案
您的问题不在于递归,而是理解 Golang 的封装,e.i.公共(public)和私有(private)成员。 为了在 Go 中进行编码,您的结构必须具有公共(public)字段(以大写字母开头):
type Dog struct {
Age int
Sibling *Dog
}
关于go - 在 go 中编码递归类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40232098/