Skip to content

Commit 6154bf5

Browse files
authored
Update go-tips.cn.md
1 parent 794419f commit 6154bf5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

go-tips.cn.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,25 @@ jsoniter.UnmarshalFromString(`"1.23"`, &val)
155155
```
156156

157157
# 容忍空数组作为对象
158+
159+
PHP另外一个令人崩溃的地方是,如果 PHP array是空的时候,序列化出来是`[]`。但是不为空的时候,序列化出来的是`{"key":"value"}`
160+
我们需要把 `[]` 当成 `{}` 处理。
161+
162+
如果你使用的是jsoniter,可以启动模糊模式来支持 PHP 传递过来的 JSON。
163+
164+
```golang
165+
import "github.com/json-iterator/go/extra"
166+
167+
extra.RegisterFuzzyDecoders()
168+
```
169+
170+
这样就可以支持了
171+
172+
```golang
173+
var val map[string]interface{}
174+
jsoniter.UnmarshalFromString(`[]`, &val)
175+
```
176+
158177
# 使用 MarshalJSON支持time.Time
159178
# 使用 RegisterTypeEncoder支持time.Time
160179
# 使用 MarshalText支持非字符串作为key的map

0 commit comments

Comments
 (0)