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 65528e9 commit 794419fCopy full SHA for 794419f
go-tips.cn.md
@@ -131,6 +131,29 @@ type TestObject struct {
131
如果json是 `{"Field1": 100}` 则会报错
132
133
# 容忍字符串和数字互转
134
+
135
+如果你使用的是jsoniter,可以启动模糊模式来支持 PHP 传递过来的 JSON。
136
137
+```golang
138
+import "github.com/json-iterator/go/extra"
139
140
+extra.RegisterFuzzyDecoders()
141
+```
142
143
+这样就可以处理字符串和数字类型不对的问题了。比如
144
145
146
+var val string
147
+jsoniter.UnmarshalFromString(`100`, &val)
148
149
150
+又比如
151
152
153
+var val float32
154
+jsoniter.UnmarshalFromString(`"1.23"`, &val)
155
156
157
# 容忍空数组作为对象
158
# 使用 MarshalJSON支持time.Time
159
# 使用 RegisterTypeEncoder支持time.Time
0 commit comments