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

JSON元帅的Stringer等效项

I can implement Stringer to specify how fmt.Print() will write my custom type as a string. Is there an equivalent for json marshal?

I want to store unique values in go and represent it as a slice in json. Using a slice in go isn't optimal for this. This O(n) insert seems unnecessary - a binary tree or map would be faster, specially since I'm keeping the list sorted at all times.

Yes, json.Marshaler and json.Unmarshaler.

Implementing MarshalJSON and UnmarshalJSON will give you what you want.

近期文章

  • Go无法检测到`sync`软件包
  • 如何在执行时忽略根JSON元素?
  • Golang构建约束随机
  • exec.Command(“ date”)无法找到日期命令
  • 如何直接从vim运行go lang代码?
  • 转:函数的变量,返回接口
  • Go中的元组分配
  • 如何离线获得Golang编程导览[关闭]
  • exec.start中的这部分代码是什么意思?
  • 范围超过结构片时的Golang内存地址问题
  • 无法运行goinstall
  • Golang正则表达式替换字符串之间
  • Golang GAE-联合登录示例
  • 去编译错误:未定义的变量
  • UItableVIewCell中放Button,有时候Button事件触发不了,求破!
  • 由GC收集时的免费C指针
  • 同时迭代两个字符串
  • 分号插入ala google go with flex
  • 在Go中使用http.NewRequest处理错误
  • Golang闭包不存储捕获的变量?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华