getRealType适配未输入数据类型的情况

This commit is contained in:
白茶清欢 2025-05-06 17:07:45 +08:00
parent c403047e9f
commit a0c2fb37e3

View File

@ -143,7 +143,8 @@ func Any(sourceValue gjson.Result) (any, error) {
func getRealDataType(dataType consts.DataType, sourceValue gjson.Result) consts.DataType { func getRealDataType(dataType consts.DataType, sourceValue gjson.Result) consts.DataType {
// 指针数据类型, 转换为普通数据类型处理 // 指针数据类型, 转换为普通数据类型处理
dataType = consts.DataType(strings.TrimLeft(dataType.String(), "*")) dataType = consts.DataType(strings.TrimLeft(dataType.String(), "*"))
if dataType == consts.DataTypeAny { // 没指定数据类型或者数据类型是any
if dataType == consts.DataTypeAny || dataType == "" {
if sourceValue.IsObject() { if sourceValue.IsObject() {
dataType = consts.DataTypeMapAnyAny dataType = consts.DataTypeMapAnyAny
} else if sourceValue.IsArray() { } else if sourceValue.IsArray() {
@ -153,6 +154,10 @@ func getRealDataType(dataType consts.DataType, sourceValue gjson.Result) consts.
} else { } else {
if sourceValue.Type == gjson.Number { if sourceValue.Type == gjson.Number {
dataType = consts.DataTypeFloat64 dataType = consts.DataTypeFloat64
} else if sourceValue.Type == gjson.String {
dataType = consts.DataTypeString
} else {
dataType = consts.DataTypeAny
} }
} }
} }