Yo_94
(Hamxa)
September 15, 2020, 12:55pm
1
I have a map that returns me the interface and that interface contains the pointer to the array object, so is there a way I can get data out of that array?
exampleMap := make(map[string]interface{})
I tried ranging over interface but I am getting error “cannot range over value (variable of type interface{})”
lutzhorn
(Lutz Horn)
September 15, 2020, 1:01pm
2
You don’t use exampleInterface
anywhere. Please show code that demonstrates your problem.
Yo_94
(Hamxa)
September 15, 2020, 1:07pm
3
I have made the change, but the interface returns me the array with pointer.
lutzhorn
(Lutz Horn)
September 15, 2020, 1:11pm
4
OK, now you have a map. Please show us how you try to iterate over it.
Yo_94
(Hamxa)
September 15, 2020, 1:18pm
5
for key, value := range exampleMap {
if key == "Struct1" {
// now here I am trying to get value which matches the key
}
}
lutzhorn
(Lutz Horn)
September 15, 2020, 1:21pm
6
I can’t reproduce your error. This works:
package main
import (
"fmt"
)
func main() {
exampleMap := make(map[string]interface{})
exampleMap["Struct1"] = "foo"
for key, value := range exampleMap {
if key == "Struct1" {
fmt.Printf("%s=%s\n", key, value)
}
}
}
Show us the code that produces your error.
1 Like
system
(system)
Closed
December 14, 2020, 1:27pm
7
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.