Range map[interface{}] interface{}

2,051 views
Skip to first unread message

Bahtiyar Biksayev

unread,
Jun 3, 2015, 10:04:23 AM6/3/15
to golan...@googlegroups.com
How can I range, got child items of map[interface{}]interface{}??

I got type interface{} does not support indexing error..

Jan Mercl

unread,
Jun 3, 2015, 10:24:21 AM6/3/15
to golan...@googlegroups.com
On Wed, Jun 3, 2015 at 4:04 PM Bahtiyar Biksayev <bahtiyar...@gmail.com> wrote:

> How can I range, got child items of map[interface{}]interface{}??
>
> I got type interface{} does not support indexing error..

Please show some code at http://play.golang.org/ demonstrating what you're trying to do.

-j

--

-j

Dustin

unread,
Jun 3, 2015, 12:16:08 PM6/3/15
to golan...@googlegroups.com
You have probably got a map[interface{}]interface{} inside of a variable of type interface{}.
You'll need to do a type assertion before ranging.

Bahtiyar Biksayev

unread,
Jun 3, 2015, 12:57:10 PM6/3/15
to golan...@googlegroups.com
I`m trying to assert it to map[string]interface{}, but I got error on it, cause there must be something like (interface{}).(map[string]interface{}), but instead of that I got (map[interface{}]interface{}).(map[string]interface{}) that`s why I got such error.

Brendan Tracey

unread,
Jun 3, 2015, 1:51:43 PM6/3/15
to golan...@googlegroups.com
Sorry, but I still don't understand what you're doing. Please provide a snippet on the playground (linked by Jan)

Rob Pike

unread,
Jun 3, 2015, 2:29:25 PM6/3/15
to Brendan Tracey, golan...@googlegroups.com
It may be unhelpful to say so, but it's true: using map[interface{}]interface{} is almost always a mistake since it eliminates all possibilities for static type checking and implies there is no useful structure to the data.

-rob


On Wed, Jun 3, 2015 at 10:51 AM, Brendan Tracey <tracey....@gmail.com> wrote:
Sorry, but I still don't understand what you're doing. Please provide a snippet on the playground (linked by Jan)

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bahtiyar Biksayev

unread,
Jun 3, 2015, 3:11:15 PM6/3/15
to golan...@googlegroups.com
Thanx everyone. Solved problem
Reply all
Reply to author
Forward
0 new messages