增加JSON解析工具
This commit is contained in:
parent
1e97af42b9
commit
ca6def0797
36
util/json.go
Normal file
36
util/json.go
Normal file
@ -0,0 +1,36 @@
|
||||
// Package util...
|
||||
//
|
||||
// Description : json 工具函数
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2021-09-14 8:38 下午
|
||||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
// JSONUnmarshalWithNumber 解析json
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 8:39 下午 2021/9/14
|
||||
func JSONUnmarshalWithNumber(byteData []byte, receiver interface{}) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(byteData))
|
||||
decoder.UseNumber()
|
||||
return decoder.Decode(receiver)
|
||||
}
|
||||
|
||||
// JSONUnmarshalWithNumberForIOReader ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 8:43 下午 2021/9/14
|
||||
func JSONUnmarshalWithNumberForIOReader(ioReader io.ReadCloser, receiver interface{}) error {
|
||||
decoder := json.NewDecoder(ioReader)
|
||||
decoder.UseNumber()
|
||||
return decoder.Decode(receiver)
|
||||
}
|
Loading…
Reference in New Issue
Block a user