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

具有自定义标签的Golang Marshal / Unmarshal json

I want to Marshal / Unmarshal Golang object (json) with a custom tag.

Like

type Foo struct {
    Bar string `json:"test" es:"bar"`
}

data, _ := json.MarshalWithESTag(Foo{"Bar"})
log.Println(string(data)) // -> {"foo":"bar"}

In other words, I whan to use the encoding/json library with a different tag here: https://github.com/golang/go/blob/master/src/encoding/json/encode.go#L1033

Thanks :)

近期文章

  • 如何将os.Stdout管道传输到golang模板
  • 如何在mGo中动态转换结果文档
  • goroutine调度如何工作
  • exec未从Golang应用程序运行命令
  • 从接口映射中摆脱空的JSON值{}
  • 使用类型查找映射解组通用json
  • 通过Goroutines运行多个GTK WebKitWebViews
  • 使用Go的crypto / ssh在Cisco Switch上运行命令
  • 时间序列数据存储
  • 在Raspberry pi pi gpio线路上Go中的事件,回调或侦听器?
  • 解析部署命令错误x509
  • 如何从字符串中删除二进制内容?
  • 将字符串转换为字段名称
  • 将Go与cgo和Xlib一起使用时出错
  • htop和golang readmemstats之间的差异
  • Golang SSH服务器:如何使用scp处理文件传输?
  • 适用于Ajax的Web刮板/爬虫
  • 在关闭套接字或写入换行符之前,TCPConn Write不会执行任何操作
  • 如何自动执行文件更改的make目标?
  • 如何用Python以外的其他语言取消/撤销延迟的任务?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华