例如:code: 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 回答
慕村225694
TA贡献1880条经验 获得超4个赞
试试这个:
package main
import (
"fmt"
)
type person struct { //struct
id int
name string
}
func main() {
var (
p []person
pi []interface{}
)
pi = append(pi, person{
id: 1,
name: "Mike",
})
for _, tmp := range pi {
// fmt.Println(tmp,k)
p = append(p, tmp.(person))
fmt.Println( p)
}
}
- 1 回答
- 0 关注
- 95 浏览
添加回答
举报
0/150
提交
取消