From 2e1ece4c82fc1e50a3af02a49af482dc41883e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 24 May 2025 18:56:28 +0800 Subject: [PATCH] =?UTF-8?q?gjson=5Fread=E4=BC=98=E5=8C=96=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- implement/gjson_read.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/implement/gjson_read.go b/implement/gjson_read.go index 9e3e66c..e11b38d 100644 --- a/implement/gjson_read.go +++ b/implement/gjson_read.go @@ -14,6 +14,7 @@ import ( "git.zhangdeman.cn/zhangdeman/json_filter/gjson_hack" "git.zhangdeman.cn/zhangdeman/serialize" "github.com/tidwall/gjson" + "strings" ) // NewGjsonRead ... @@ -53,7 +54,14 @@ func (g *gjsonRead) Type(dataPath string) string { case gjson.String: return consts.DataTypeString.String() case gjson.Number: - return consts.DataTypeFloat64.String() + valStr := pathRes.String() + if strings.Contains(valStr, ".") { + return consts.DataTypeFloat64.String() + } + if strings.HasPrefix(valStr, "-") { + return consts.DataTypeInt64.String() + } + return consts.DataTypeUint64.String() case gjson.Null: return consts.DataTypeAny.String() case gjson.True, gjson.False: @@ -63,15 +71,15 @@ func (g *gjsonRead) Type(dataPath string) string { } func (g *gjsonRead) Int(dataPath string) (int64, error) { - return gjson_hack.Int(g.gjsonResult.Get(dataPath)) + return gjson_hack.Int[int64](g.gjsonResult.Get(dataPath)) } func (g *gjsonRead) Uint(dataPath string) (uint64, error) { - return gjson_hack.Uint(g.gjsonResult.Get(dataPath)) + return gjson_hack.Uint[uint64](g.gjsonResult.Get(dataPath)) } func (g *gjsonRead) Float(dataPath string) (float64, error) { - return gjson_hack.Float64(g.gjsonResult.Get(dataPath)) + return gjson_hack.Float[float64](g.gjsonResult.Get(dataPath)) } func (g *gjsonRead) Bool(dataPath string) (bool, error) {