首页 > 其他分享 >beego:interface conversion: interface {} is string, not int

beego:interface conversion: interface {} is string, not int

时间:2023-06-13 15:02:54浏览次数:34  
标签:src conversion beego string int go usr interface local


代码

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()


标签:src,conversion,beego,string,int,go,usr,interface,local
From: https://blog.51cto.com/u_16159391/6470221

相关文章

  • 在使用VScode编辑器vue开发过程中,v-for在Eslint的规则检查下出现报错:Elements in iter
    报错如下: 该怎么解决呢?现在说说解决他的两种方法:1.直接在v-for循环后面绑定一个属性,跟前面需要循环的属性一一对应,截图如下:  2.在vscode中去掉Eslint规则检查,具体操作截图如下:文件–》首选项–》设置–》在搜索框中输入:vetur.validation.template,找到之后将前面的打钩......
  • Intel Quick Sync Video(QSV)
    安装和使用过程:1.InstallIntelMediaServerStudioforLinux.Downloadfromsoftware.intel.com/intel-media-serverstudio.Thisisaprerequisiteforthe*_qsvcodecsasitprovidesthefoundationforencodeacceleration.Seethenextchapterformoreinfoon......
  • 【MySQL的CheckPoint技术】
    MySQL的CheckPoint(CheckPoint)技术,又称"redolog"(Redolog),是MySQL数据库的核心技术之一,其目的是在发生故障或故障时,保证数据库中存储的数据可以得到有效的修复。对数据库进行的修改,包括写入,更新,删除等,都要进行相应的文档化,以确保数据在任何时候都是一致的。如何使用MySQL检查......
  • int型转QByteArray(30转成0x1e,0x00)
    int转QByteArrayQByteArrayintToByte(inti){QByteArrayabyte0;abyte0.resize(4);abyte0[0]=(uchar)(0x000000ff&i);abyte0[1]=(uchar)((0x0000ff00&i)>>8);abyte0[2]=(uchar)((0x00ff0000&i)>>16......
  • 外汇天眼:FINTOCH又传诈骗案! 新竹妇人入金149万领不回
    最近网络爆出多起资金盘诈骗案,除了引发社会大众关注的「imB诈骗案」外,上个月外汇天眼也发布了「投资人注意!FINTOCH“分投趣”遭爆为假借贷资金盘! 」这篇文章,呼吁所有用户小心这个平台,没想到前几天又出现新的受害者。从外汇天眼之前的报道可以知道,FINTOCH借贷理财收益每天报酬率有......
  • HDU 5489 Removed Interval(DP)
    题意:求去掉某一个长度为L的子串的LIS思路:画画图其实比较显然的想法是去掉这个区间的时候答案是右边以第一个数开头的LIS+左边最后一个数小于右边第一个数的LIS,为什么是右边以第一个数开头的LIS呢,因为如果是在这个L的后第二个是最佳答案的话那么我在这个“窗口”滑到L+1这个位置的时......
  • Intersection Observer
    IntersectionObserver在日常开发中,经常会遇到对数据、图片进行懒加载的处理,要判断用户是否已经看到了数据或者图片。之前用的方法是通过听到scroll事件或者使用setInterval来判断,这种方法的缺点是,由于scroll事件触发频率高,计算量很大,如果不做防抖节流的话,很容易造成性能问题,而se......
  • 解决在 PyCharm 中,logging 与 print 交错的问题
    项目配置->配置->执行->在输出控制台中模拟终端将它勾上即可推测是由于控制台和运行的输出逻辑不同导致的......
  • struts2 intercepter简单例子
    玩了一天终于把struts2的intercepter搞明白了,有那么点小兴奋,呵呵。下面把俺的成果分享一下:1.在注册页面中(index.jsp)注册一下:  <%session.setAttribute("user","lzw");%>2.在登录界面(login.jsp)登录:<formaction="login.action"method="post"><......
  • cpp: Interpreter Pattern
     /*****************************************************************//***\fileDuSimple.h*\briefInterpreterPattern解释器模式C++14*2023年6月10日涂聚文GeovinDuVisualStudio2022edit.*\authorgeovindu*\dateJune2023**********......