go 打印结构体指针数组
序列化后输出。
package main
import (
"encoding/json"
"fmt"
)
type Student struct {
Age int
Name string
}
func printStructPointerSlice(data interface{}) string {
bytes, err := json.Marshal(data)
if err != nil {
fmt.Println(err)
return ""
}
return string(bytes)
}
func main() {
s := []*Student{{Age: 17, Name: "abc"}, {Age: 18, Name: "efg"}}
fmt.Printf("%v %+v\n", s, s)
fmt.Printf("%s\n", printStructPointerSlice(s))
}