Created
October 12, 2019 03:00
-
-
Save lachlan-eagling/14c27855e149114855fa6b1ff48d3b7e to your computer and use it in GitHub Desktop.
Blog - Anatomy of a Struct (Unmarshaling Array)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
var users []User | |
userJson := []byte(`[{"firstName": "Lachlan", "surname": "Eagling", "username": "Lachlan_E", "age": 28}, {"firstName": "Jon", "surname": "Snow", "username": "Watcher21", "age": 20}]`) | |
if err := json.Unmarshal(userJson, &users); err != nil { | |
fmt.Println(err) | |
} | |
fmt.Println(users) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment