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:
jeffery
2023-05-12 18:44:30 +08:00
committed by GitHub
parent 6f6ea53714
commit da0e416c8d
6 changed files with 149 additions and 64 deletions

View File

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