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

外部软件包的自定义golang JSON封送处理

How can I add custom JSON marshaling to structs from external packages? I am unable to add the MarshalJSON and UnmarshalYAML to these structs.

You could add that struct to one defined by you. Then add the functions MarshalJSON and UnmarshalYAML to your struct:

type YourStruct struct {
    ImportedStruct
}

func (s *YourStruct) MarshalJSON() ([]byte, error) {
    ...
}

近期文章

  • 20060102150405是什么意思?
  • 无法建立开源项目
  • 为什么Go的频道可以关闭两次?
  • 如何将os.Exec中的stdout传送到文件和终端?
  • 处理条件异步函数的返回数据的惯用方式是什么?
  • `sync.WaitGroup`的方法是什么?
  • 使用Golang模板动态获取变量
  • 发生异常时继续执行循环
  • 如何在类型转换中区分符文和int32值?
  • GoLang打印数组中值的出现次数
  • Go的。(type)取消编组JSON时发生意外
  • 将int64(从UnixNano)转换为位置时间字符串
  • Golang:使用循环切片/地图范围注册多个路由
  • 如何为GoClipse设置GoCode?
  • tar存档保留硬链接
  • Golang中Go例程的开销
  • 使用指针将列表复制到列表
  • 从Go中的派生类型调用方法
  • 料滴尝试解码nil值会导致EOF错误
  • 您如何从Go中的int转换溢出中得到错误?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华