6-1 json 序列化

package main

import (
    "encoding/json"
    "fmt"
)

type Persion struct {
    Name string
    Age  int
    Rmb  float64
    Sex  bool
    Hobby []string
}

func main() {
persion :
= Persion{"谦哥", 50, 123.45, true, []string{"抽烟", "喝酒", "烫头"}} //使用json包序列化结构体 bytes, e := json.Marshal(persion) if e != nil { fmt.Printf("序列化失败,err=",e) return } fmt.Println(string(bytes)) }