此问题在此处已有答案:
How do I convert from a slice of interface{} to a slice of my struct type in Go? [duplicate](2个答案)
Type converting slices of interfaces(9个答案)
去年关闭了。
例如,以下代码:
type person struct { //struct
id int
name string
}
func example() {
var (
p []person
pi []interface{}
)
pi = append(pi, person{
id: 1,
name: "Mike",
})
}
如何将pi
转换为p
?
1条答案
按热度按时间wz1wpwve1#
试试这个: