struct和[]byte的转换,注意结构体内变量首字母一定大写

type temp struct {
    Afd int
    Bee string
}
func main(){
  text:=temp{3123,"4234"}
  b._:=json.Marshal(text)
var text2 temp
  err:=json.Unmarshal(b,&text2)
  fmt.Println(err,text2)
}

temp结构体内的Afd和Bee首字母一定大写,否则无法序列化和反序列化
posted @ 2017-07-26 16:00  kekemuyu  Views(201)  Comments(0Edit  收藏  举报