代码如下:
node, _ := html.Parse(response.Body)
nodeString,err := json.Marshal(node)
fmt.Println(err)
报异常如下:
json: unsupported value: encountered a cycle via *html.Node
是因为 Node 包含了*Node 类型的字段?对于这种循环嵌套的对象有办法做到序列化吗?
附 Node 的代码
type Node struct {
Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node
Type NodeType
DataAtom atom.Atom
Data string
Namespace string
Attr []Attribute
}
