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

一、场景

  • 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}

猜你喜欢

转载自blog.csdn.net/qq_36025814/article/details/111840756