get keys from the interface

So as I just finished writing this question I figured out the map was the correct way to get my data.

Posted the question and answering it myself because I thought it would be useful for others

type Data struct {
        Devices map[int]interface{} `json:"devices" bson:"devices"`

for key, value := range deviceIds.Devices {
        fmt.Println(key, value)

Changing the struct to the above map and then looping through it with range worked perfectly

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top