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 1/2] =?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 From a0c2fb37e3f80307d564c523e9ccf746fe1143b3 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:07:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?getRealType=E9=80=82=E9=85=8D=E6=9C=AA?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gjson_hack/precision.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gjson_hack/precision.go b/gjson_hack/precision.go index 9d1d8f5..d2c3461 100644 --- a/gjson_hack/precision.go +++ b/gjson_hack/precision.go @@ -143,7 +143,8 @@ func Any(sourceValue gjson.Result) (any, error) { func getRealDataType(dataType consts.DataType, sourceValue gjson.Result) consts.DataType { // 指针数据类型, 转换为普通数据类型处理 dataType = consts.DataType(strings.TrimLeft(dataType.String(), "*")) - if dataType == consts.DataTypeAny { + // 没指定数据类型或者数据类型是any + if dataType == consts.DataTypeAny || dataType == "" { if sourceValue.IsObject() { dataType = consts.DataTypeMapAnyAny } else if sourceValue.IsArray() { @@ -153,6 +154,10 @@ func getRealDataType(dataType consts.DataType, sourceValue gjson.Result) consts. } else { if sourceValue.Type == gjson.Number { dataType = consts.DataTypeFloat64 + } else if sourceValue.Type == gjson.String { + dataType = consts.DataTypeString + } else { + dataType = consts.DataTypeAny } } }