package main import ( "log" json "github.com/json-iterator/go" ) // Implement interface type Address struct { City string State string Post string *Person } // Implement interface type Person struct { Name string Age int *Address } func main() { A := Address{ City: "New York", State: "NY", } p := Person{ Name: "Alice", Age: 30, Address: &A, } A.Person = &p marshal, err := json.Marshal(&p) if err != nil { log.Printf("Marshal failed: %v", err) } else { log.Printf("format: %s", marshal) } } Address include Person Point Person include Address Point json "github.com/json-iterator/go" <img width="718" height="76" alt="Image" src="https://github.com/user-attachments/assets/7cf57e84-f0a0-4de6-bfd9-03eb592bc307" /> Use"encoding/json" <img width="1114" height="85" alt="Image" src="https://github.com/user-attachments/assets/67211b40-131d-4108-aff2-6bb9dd280e75" />
package main
import (
"log"
)
// Implement interface
type Address struct {
City string
State string
Post string
*Person
}
// Implement interface
type Person struct {
Name string
Age int
*Address
}
func main() {
A := Address{
City: "New York",
State: "NY",
}
p := Person{
Name: "Alice",
Age: 30,
Address: &A,
}
A.Person = &p
}
Address include Person Point
Person include Address Point
json "github.com/json-iterator/go"
Use"encoding/json"