> How do I iterate over a map[string] interface{}
It's a normal map, and you don't need reflection to iterate over it or
consider the value type. For example:
for key, value := range yourMap {
if s, ok := value.(string); ok {
fmt.Printf("%q is a string: %q\n", key, s)
}
}
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/plus
http://niemeyer.net/twitter
http://niemeyer.net/blog
-- I'm not absolutely sure of anything.
Same way:
if items, ok := map["items"].([]string) {
...
On Tue, Apr 10, 2012 at 13:18, DEXTER MCCONNELL <djc...@gmail.com> wrote:Same way:
> How do I access the map when it contains an array of strings ?
>
> map["response"] = "Blah Blah...."
> map["items"] = make([]string, 0)
>
> I am be to access the values of response, how do I access the value of items?
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/plus
http://niemeyer.net/twitter
http://niemeyer.net/blog
-- I'm not absolutely sure of anything.
http://play.golang.org/p/UPqmVngVPy
if items, ok := response["items"].([]string); ok {
...
}
Assignments in go don't have a value and can't be tested.
On Tue, Apr 10, 2012 at 13:18, DEXTER MCCONNELL <djc...@gmail.com> wrote:
> I got this error
> When I accessed using
> if items, ok := response["items"].([]string) {
> ...
> }
>
>
> items, ok = response["items"].([]string) used as value
--
matt kane's brain
http://hydrogenproject.com