0
我有以下结构:Golang反映越来越结构成员在片中
type ProductionInfo struct {
StructA []struct {
Field1 string
Field2 int
}
我就从StructA在ProductionInfo类型字段中提取名称和类型。但我不明白如何。有谁能够帮助我?
我有以下结构:Golang反映越来越结构成员在片中
type ProductionInfo struct {
StructA []struct {
Field1 string
Field2 int
}
我就从StructA在ProductionInfo类型字段中提取名称和类型。但我不明白如何。有谁能够帮助我?
使用reflect包:
f, _ := reflect.TypeOf(ProductionInfo{}).FieldByName("StructA")
t := f.Type.Elem()
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
fmt.Println(f.Name, f.Type)
}
塞赖斯你是男人..谢谢。我已经在使用反射,但没有使用FieldByName。非常感谢 – Davide