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