xxxxxxxxxx
package main
import (
"encoding/json"
"fmt"
)
type Person struct {
Name string
Age int
Email string
}
func main() {
// Example JSON data
jsonData := `{"name":"John Doe","age":30,"email":"john.doe@example.com"}`
// Create a variable of type Person
var person Person
// Unmarshal the JSON data into the person variable
err := json.Unmarshal([]byte(jsonData), &person)
if err != nil {
fmt.Println("Error:", err)
return
}
// Access the struct fields
fmt.Println("Name:", person.Name)
fmt.Println("Age:", person.Age)
fmt.Println("Email:", person.Email)
}
xxxxxxxxxx
type response2 struct {
Page int `json:"page"`
Fruits string `json:"fruits"`
}