go icon indicating copy to clipboard operation
go copied to clipboard

Bug:Dead Loop Two when Two structs are mutually dependent。

Open jau1jz opened this issue 1 month ago • 0 comments

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"

Image

Use"encoding/json"

Image

jau1jz avatar Nov 20 '25 08:11 jau1jz