Skip to content

Commit 8c33641

Browse files
authored
Update go-tips.cn.md
1 parent aceb337 commit 8c33641

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

go-tips.cn.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,17 @@ should.Equal(`{"user_name":"taowen","first_language":"Chinese"}`, string(output)
297297
```
298298

299299
# 使用私有的字段
300+
301+
Go 的标准库只支持 public 的 field。jsoniter 额外支持了 private 的 field。需要使用 `SupportPrivateFields()` 来开启开关。
302+
303+
```golang
304+
import "github.com/json-iterator/go/extra"
305+
306+
extra.SupportPrivateFields()
307+
type TestObject struct {
308+
field1 string
309+
}
310+
obj := TestObject{}
311+
jsoniter.UnmarshalFromString(`{"field1":"Hello"}`, &obj)
312+
should.Equal("Hello", obj.field1)
313+
```

0 commit comments

Comments
 (0)