Golang解析json,结构体生成Json以及MD5加密
package main
import (
"encoding/json"
"fmt"
)
//成员变量名首字母必须大写
type IT struct {
Company string
Subjects []string
IsOk bool
Price float64
}
func main() {
//定义一个结构体变量,同时初始化
s := IT{"itcast", []string{"Go", "C++", "Python", "Test"}, true, 666.666}
//编码,根据内容生成json文本
buf, err := json.Marshal(s)
if err != nil {
fmt.Println("err = ", err)
return
}
fmt.Println("buf = ", string(buf))
}