Skip to content

Instantly share code, notes, and snippets.

@avelino
Created July 8, 2014 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avelino/70d79132da48cbff1b80 to your computer and use it in GitHub Desktop.
Save avelino/70d79132da48cbff1b80 to your computer and use it in GitHub Desktop.
f = map[string]interface{}{
"Name": "Wednesday",
"Age": 6,
"Parents": []interface{}{
"Gomez",
"Morticia",
},
}
m := f.(map[string]interface{})
for k, v := range m {
switch vv := v.(type) {
case string:
fmt.Println(k, "is string", vv)
case int:
fmt.Println(k, "is int", vv)
case []interface{}:
fmt.Println(k, "is an array:")
for i, u := range vv {
fmt.Println(i, u)
}
default:
fmt.Println(k, "is of a type I don't know how to handle")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment