mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-09 08:50:25 +08:00
Feature(v2):jsonToStruct supports interface type assignment (#41)
* Feature(v2):jsonToStruct supports interface type assignment close #38 - `JsonToStruct` 支持基本数据类型中定义 `interface{}` - `JsonToStruct` 支持基本数据类型中定义 `any` - 对于 `parsePrimitiveValue` 的 `string` 类型转义兼容 - 对于 `parsePrimitiveValue` 的 `bool` 类型转义兼容
This commit is contained in:
@@ -99,6 +99,12 @@ func JsonToStruct(jsonData string, result any) error {
|
||||
} else {
|
||||
return fmt.Errorf("unexpected value type for slice: %T", value)
|
||||
}
|
||||
case reflect.Interface:
|
||||
if value == nil {
|
||||
fieldValue.Set(reflect.Zero(fieldType.Type))
|
||||
} else {
|
||||
fieldValue.Set(reflect.ValueOf(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user