getRealDataType尅性识别优化 + Value 泛解析支持更多数据类型

This commit is contained in:
白茶清欢 2025-05-06 17:04:20 +08:00
parent 777a5cb93c
commit c403047e9f

View File

@ -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