栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

golang:cannot unmarshal number into Go value of type []json.RawMessage

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

golang:cannot unmarshal number into Go value of type []json.RawMessage

  • 一、场景
  • 二、proto文件内容
  • 三、解决

一、场景
  • Micro Web 接口请求,传参内容如下
{"ids": 1}
  • 报错:cannot unmarshal number into Go value of type []json.RawMessage
  • 翻译:无法将数字解编为类型为[]的Go值json.RawMessage
  • 分析:不能把数字解析为[],应该是要传数组[1],而不是传数字1
二、proto文件内容
message GoodsRequest {
    int64 id = 1;
    repeated int64 ids = 2;
    double sale_price = 3;
    string desc = 4;
    repeated GoodsSku tags = 5;
}

message GoodsSku {
    int64 id = 1;
    int64 goods_id = 2;
    string name = 3;
    int64 type= 4;    
    double market_price = 5;
}
三、解决
  • 参数方式传错了,正确的方式为:
{"ids": [1, 2]}
  • id的传参方式如下:
{"id": 1}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/944689.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号