From ca6def07978ab4a62878e4129fc3fa621c1566f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 14 Sep 2021 20:45:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0JSON=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/json.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 util/json.go diff --git a/util/json.go b/util/json.go new file mode 100644 index 0000000..93081cd --- /dev/null +++ b/util/json.go @@ -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) +}