According to this question and the go code scanning queryrow to an existing map[string]interface{} in go, I am trying to get ## The keys and values of #data["id"]
func login() func(c *lmhttp.context, code int, data interface{}) (int, interface{}) { return func(c *lmhttp.context, code int, data interface{}) (int, interface{}) { map_data := data.(map[string]interface{}) fmt.print(map_data, map_data["id"]) } }
interface conversion: interface {} is loginresp, not map[string]interface {}
response code like this:
func (c *Context) Response(data interface{}) { c.result(http.StatusOK, data) }
marshal to get the
json data, and then
map and
unmarshalit,
json_str, jsonErr := json.Marshal(data) if json_str != nil { fmt.Printf("%v", jsonErr) } m := make(map[string]interface{}) err := json.Unmarshal([]byte(json_str), &m) if err != nil { fmt.Println(err) fmt.Println("This is ID", m["id"]) }
The above is the detailed content of How to get the value of interface{} in Go? (Interface conversion: interface{} is Resp, not mapinterface{}). For more information, please follow other related articles on the PHP Chinese website!