import ( "fmt" "github.com/mailru/easyjson/jlexer" ) func main() { data := `{"name": "John", "age": 32}` lexer := jlexer.Lexer{Data: []byte(data)} lexer.Delim('{') for !lexer.IsDelim('}') { key := lexer.UnsafeString() lexer.WantColon() value := lexer.UnsafeString() fmt.Printf("%s: %s\n", key, value) if !lexer.Next() { break } } }
import ( "fmt" "github.com/mailru/easyjson/jlexer" ) type Person struct { Name string `json:"name"` Age int `json:"age"` } func main() { data := `{"name": "John", "age": 32}` lexer := jlexer.Lexer{Data: []byte(data)} var p Person p.UnmarshalEasyJSON(&lexer) fmt.Printf("%+v\n", p) }This code defines a Person struct and then reads the JSON data into a person object using the UnmarshalEasyJSON method of the Person struct.