我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

无法将类型* json.RawMessage的表达式转换为golang中的[] byte类型

code and error message

I was experiencing this problem when using golang's elasticsearch client "elastic".

*json.RawMessage is a type of []byte.If I not write []byte() to cast type, it said cannot use 'resp.Source' (type *json.RawMessage) as type []byte.

The environment is go 1.10.3 and elastic 6.x

A *json.RawMesasge is not a []byte. It's a pointer.

Dereference the pointer to convert to a slice of bytes:

 byteSlice := []byte(*pointerToRawMessage)

近期文章

  • 切片与容器/列表之间的差异
  • 如何将结构作为二进制数据写入golang中的文件?
  • 使用Delve调试时将参数传递给可执行文件
  • 如何获取管道过程的退出代码?
  • 通过Golang中的方法更改类型的基础值
  • 封送至JSON时转换类型
  • 如何将多个变量传递给Go HTML模板
  • 用time.Time去类型开关
  • 即使配置了GOPTH,也无法下载fabric-sdk-go
  • “执行构建”命令后无法找到可执行文件/二进制文件
  • 如何在Golang中解开python对象
  • 通过switch语句分配类型/创建结构
  • 例行生产者-消费者模式恐慌
  • 类型断言会改变go中的值吗?
  • 使用分块传输编码处理请求
  • Golang valyala / fasthttp如何获取数组中的所有标头?
  • 将JSON导入Map
  • 如何从Go lang中的数据库中获取数据
  • C或C ++析构函数中模拟GO语言延迟的实用方法是什么?
  • Go如何导入解析依赖项?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华