代码
organizationId := info[0]["organization_id"].(int)
报错
beego_api:interface conversion: interface {} is string, not int
Request Method: GET
Request URL: /v1/board2/students/detail2?id=237497
RemoteAddr: ::1
Stack
/usr/local/go/src/runtime/panic.go:522
/usr/local/go/src/runtime/iface.go:248
/Users/wxx/go/src/beego_api/controllers/board2/students.go:80
/usr/local/go/src/reflect/value.go:447
/usr/local/go/src/reflect/value.go:308
/Users/wxx/go/src/github.com/astaxie/beego/router.go:852
/usr/local/go/src/net/http/server.go:2774
/usr/local/go/src/net/http/server.go:1878
/usr/local/go/src/runtime/asm_amd64.s:1337
beego 1.11.1 (beego framework)
golang version: go1.12
最后代码修改成
// 这里的类型是interface{}
organizationId := info[0]["organization_id"]
// 这里先显示转换,.(string) 把interface转换成string类型,再利用strconv.Atoi把string 转换成int
organizationId2,_ := strconv.Atoi(organizationId.(string))
string转换成int
strconv.Atoi()
int 转换成string
strconv.Itoa()