Skip to content

Commit 5a6ab69

Browse files
authored
Create go-tips.cn.md
1 parent e515158 commit 5a6ab69

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

go-tips.cn.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
layout: default
3+
title: Go JSON 使用小技巧
4+
---
5+
6+
* TOC
7+
{:toc}
8+
9+
有的时候上游传过来的字段是string类型的,但是我们却想用变成数字来使用。
10+
本来用一个`json:",string"` 就可以支持了,如果不知道golang的这些小技巧,就要大费周章了。
11+
12+
# 临时忽略struct字段
13+
# 临时粘合两个struct
14+
# 一个json切分成两个struct
15+
# 临时改名struct的字段
16+
# 用字符串传递数字
17+
# 容忍字符串和数字互转
18+
# 容忍空数组作为对象
19+
# 使用 MarshalJSON支持time.Time
20+
# 使用 RegisterTypeEncoder支持time.Time
21+
# 使用 MarshalText支持非字符串作为key的map
22+
# 使用 json.RawMessage
23+
# 使用 json.Number
24+
# 统一更改字段的命名风格
25+
# 使用私有的字段

0 commit comments

Comments
 (0)