import ( "fmt" "github.com/pquerna/ffjson/fflib/v1" ) type Person struct { Name string `json:"name"` Age int `json:"age"` } func main() { p := Person{Name: "Alice", Age: 30} buf := fflib.NewEncodingBuffer() err := fflib.WriteJSON(buf, &p) if err != nil { panic(err) } fmt.Println(buf.String()) }
import ( "bytes" "fmt" "github.com/pquerna/ffjson/fflib/v1" ) type Person struct { Name string `json:"name"` Age int `json:"age"` } func main() { jsonString := `{"name":"Alice","age":30}` buf := bytes.NewBufferString(jsonString) p := new(Person) err := fflib.ReadJSON(buf, p) if err != nil { panic(err) } fmt.Printf("Name: %s\n", p.Name) fmt.Printf("Age: %d\n", p.Age) }In this example, we read JSON-encoded data from a buffer using an EncodingBuffer. We then unmarshal the JSON data into a struct called "Person". The "ReadJSON" function is provided by the "github.com/pquerna.ffjson.fflib.v1" package library and is used to read JSON-encoded data from a buffer.