Skip to content

Instantly share code, notes, and snippets.

@madflojo
Created November 26, 2020 21:47
Show Gist options
  • Save madflojo/8e3a0c3cd620958edc38a34be09bf3a3 to your computer and use it in GitHub Desktop.
Save madflojo/8e3a0c3cd620958edc38a34be09bf3a3 to your computer and use it in GitHub Desktop.
maps.vs.struct.interfacearray
// Print out the JSON Numbers
var nums []int
i, ok := data["numbers"].([]interface{})
if ok {
for _, v := range i {
x, ok := v.(float64)
if !ok {
// set to default
nums = []int{}
break
}
nums = append(nums, int(x))
}
}
fmt.Printf("Numbers are")
for _, v := range nums {
fmt.Printf(" %d", v)
}
fmt.Printf("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment