From c403047e9fb6060babae848a4b3e6b876ca2d364 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, 6 May 2025 17:04:20 +0800 Subject: [PATCH] =?UTF-8?q?getRealDataType=E5=B0=85=E6=80=A7=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E4=BC=98=E5=8C=96=20+=20Value=20=E6=B3=9B=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gjson_hack/precision.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gjson_hack/precision.go b/gjson_hack/precision.go index 9423e5e..9d1d8f5 100644 --- a/gjson_hack/precision.go +++ b/gjson_hack/precision.go @@ -148,8 +148,10 @@ func getRealDataType(dataType consts.DataType, sourceValue gjson.Result) consts. dataType = consts.DataTypeMapAnyAny } else if sourceValue.IsArray() { dataType = consts.DataTypeSliceAny + } else if sourceValue.IsBool() { + dataType = consts.DataTypeBool } else { - if sourceValue.Num != 0 { + if sourceValue.Type == gjson.Number { dataType = consts.DataTypeFloat64 } } @@ -362,9 +364,9 @@ func Value(dataType consts.DataType, sourceValue gjson.Result, defaultValue any) dataType = getRealDataType(dataType, sourceValue) strVal := wrapper.String(sourceValue.String()) switch dataType { - case consts.DataTypeInt: + case consts.DataTypeInt, consts.DataTypeInt8, consts.DataTypeInt16, consts.DataTypeInt32, consts.DataTypeInt64: return Int(sourceValue) - case consts.DataTypeUint: + case consts.DataTypeUint, consts.DataTypeUint8, consts.DataTypeUint16, consts.DataTypeUint32, consts.DataTypeUint64: return Uint(sourceValue) case consts.DataTypeFloat64, consts.DataTypeFloat32: return Float64(sourceValue) @@ -374,6 +376,7 @@ func Value(dataType consts.DataType, sourceValue gjson.Result, defaultValue any) case consts.DataTypeString: return sourceValue.String(), nil case consts.DataTypeAny: + // 经过getRealDataType类型处理后依旧是any,不考虑精度问题 return sourceValue.Value(), nil case consts.DataTypeSliceAny: // 任意类型的list