We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d2c49ce commit a17acafCopy full SHA for a17acaf
go-tips.cn.md
@@ -203,6 +203,19 @@ should.Equal(`{"Field":123}`, string(bytes))
203
```
204
205
# 使用 RegisterTypeEncoder支持time.Time
206
+
207
+jsoniter 能够对不是你定义的type自定义JSON编解码方式。比如对于 time.Time 可以用 epoch int64 来序列化
208
209
+```golang
210
+import "github.com/json-iterator/go/extra"
211
212
+extra.RegisterTimeAsInt64Codec(time.Microsecond)
213
+output, err := jsoniter.Marshal(time.Unix(1, 1002))
214
+should.Equal("1000001", string(output))
215
+```
216
217
+如果要自定义的话,参见 `RegisterTimeAsInt64Codec` 的实现代码
218
219
# 使用 MarshalText支持非字符串作为key的map
220
# 使用 json.RawMessage
221
# 使用 json.Number
0 commit comments