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 794419f commit 6154bf5Copy full SHA for 6154bf5
go-tips.cn.md
@@ -155,6 +155,25 @@ jsoniter.UnmarshalFromString(`"1.23"`, &val)
155
```
156
157
# 容忍空数组作为对象
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
173
+var val map[string]interface{}
174
+jsoniter.UnmarshalFromString(`[]`, &val)
175
176
177
# 使用 MarshalJSON支持time.Time
178
# 使用 RegisterTypeEncoder支持time.Time
179
# 使用 MarshalText支持非字符串作为key的map
0 commit comments