Created
November 26, 2020 21:47
-
-
Save madflojo/8e3a0c3cd620958edc38a34be09bf3a3 to your computer and use it in GitHub Desktop.
maps.vs.struct.interfacearray
This file contains hidden or 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
// 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