JSON的庫git
JSON編碼github
func Marshal(v interface{}) ([]byte,error)json
package main import ( "fmt" "encoding/json" ) type Student struct{ Name string `json:"student_name"` Age int sex string } func main() { // 對數組類型的 json 編碼 x := [5]int{1,2,3,4,5} s1, err1 := json.Marshal(x) if err1 != nil { panic(err1) } fmt.Println(string(s1)) // 對map類型進行json編碼 m := make(map[string]int) m["zhangsan"] = 1 s2, err2 := json.Marshal(m) if err2 != nil { panic(err2) } fmt.Println(string(s2)) // 對 對象 類型進行json編碼 student := Student{"zhangsan",26,"男"} s3,err3 := json.Marshal(student) if err3 != nil { panic(err3) } fmt.Println(string(s3)) }
[1,2,3,4,5] {"zhangsan":1} {"student_name":"zhangsan","Age":26}
JSON解碼數組
func Unmarshal(data []byte,interface{}) error編碼
// 對s3進行json解碼 var s4 interface{} json.Unmarshal([]byte(s3),&s4) fmt.Printf("%v", s4)
map[student_name:zhangsan Age:26]
MD5的庫 Go語言內置的crypto/md5 的標準庫code
import ( "fmt" "crypto/md5" ) func main() { Md5Inset := md5.New() Md5Inset.Write([]byte("zhangsan")) Result := Md5Inset.Sum([]byte("")) fmt.Printf("%x\n\n", Result) }
01d7f40760960e7bd9443513f22ab9af