package main
import (
"encoding/json" // json
"fmt"
)
//github.com/pquerna/ffjson/ffjson
// json , json
// , ,
type worker struct {
Name string `json:"worker_name"` // json ,key worker_name
Sex string
salay int32 // ,json , , salay
}
func main() {
// 1、 ,
x := [5]int{1, 2, 3, 4, 5}
bytes, e := json.Marshal(x)
if e != nil {
panic(e)
}
fmt.Println(string(bytes)) //[1,2,3,4,5]
// 2、 map , json
var stu = map[string]string{}
stu = make(map[string]string)
stu["name"] = "beijing"
stuJson, err := json.Marshal(stu)
if err != nil {
panic(err)
}
fmt.Println(string(stuJson)) //{"name":"beijing"}
// 3、 struct JSON
wk := worker{
Name: "xiaozhang",
Sex: "male",
salay: 34,
}
wrJson, err2 := json.Marshal(wk)
if err2 != nil {
panic(err2)
}
fmt.Println(string(wrJson)) //{"worker_name":"xiaozhang","Sex":"male"}
// 4、 wrJson
var w interface{} // interface,
json.Unmarshal(wrJson, &w)
fmt.Printf("---json ---->%v", w) //map[worker_name:xiaozhang Sex:male]
}
==================================
package main
import (
"crypto/md5"
"fmt"
)
// ,md5
//md5 ,
// , ,copy 。
func main() {
Md5Inst := md5.New()
Md5Inst.Write([]byte("admin"))
Result := Md5Inst.Sum([]byte(""))
fmt.Printf("%x
", Result)
}