encoding/json
json.Unmarshal
import "encoding/json"
type User struct {
Name string
Age int
}
var jsonData = `[{"Name":"John", "Age":30}, {"Name":"Jane", "Age":40}]`
func main() {
var users []User
err := json.Unmarshal([]byte(jsonData), &users)
if err != nil {
panic(err)
}
for _, user := range users {
println(user.Name, user.Age)
}
}
jsonDatajson.Unmarshal&users