Problem
Fetching data from map
Data Format
res = map[Event_dtmReleaseDate:2009-09-15 00:00:00 +0000 +00:00 Trans_strGuestList:<nil> strID:TSTB]
Note
How to get the following value from the above result
Event_dtmReleaseDate
strID
Trans_strGuestList
What i tried:
res.Map("Event_dtmReleaseDate");
Error : res.Map undefined (type map[string]interface {} has no field or method Map)
res.Event_dtmReleaseDate;
Error: v.id undefined (type map[string]interface {} has no field or method id)
Best Answer
Your variable is a
map[string]interface {}
which means the key is a string but the value can be anything. In general the way to access this is:Or in the case of a string value:
Note that this will panic if the type is not correct or the key does not exist in the map, but I suggest you read more about Go maps and type assertions.
Read about maps here: http://golang.org/doc/effective_go.html#maps
And about type assertions and interface conversions here: http://golang.org/doc/effective_go.html#interface_conversions
The safe way to do it without a chance to panic is something like this: