1024programmer Java Golang language JSONmd5

Golang language JSONmd5

package main

 import (
     "encoding/json" //Built-in json tool

 // This json tool is much more efficient than the built-in json
 // And the interface is exactly the same,
 type worker struct {
     Name string `json:"worker_name"` //When converted to json format, the key is worker_name
     Sex string
     salay int32 //Note that when using json, this attribute will not be operated because salay is lowercase.

 func main() {
     // 1. Encode the array form
     x := [5]int{1, 2, 3, 4, 5}
     bytes, e := json.Marshal(x)

     if e != nil {
     fmt.Println(string(bytes)) //[1,2,3,4,5]

     // 2. For the map type, perform json
     var stu = map[string]string{}
     stu = make(map[string]string)
     stu["name"] = "beijing"
     stuJson, err := json.Marshal(stu)

     if err != nil {
     fmt.Println(string(stuJson)) //{"name":"beijing"}
     // 3. Encode the struct object in JSON format
     wk := worker{
         Name: "xiaozhang",
         Sex: "male",
         salay: 34,
     wrJson, err2 := json.Marshal(wk)

     if err2 != nil {

     fmt.Println(string(wrJson)) //{"worker_name":"xiaozhang","Sex":"male"}

     // 4. Decode wrJson
     var w interface{} //Declare an interface to store the decoded value
     json.Unmarshal(wrJson, &w)
     fmt.Printf("---json format decoding---->%v", w) //map[worker_name:xiaozhang Sex:male]

package main

 import (

 //Note that md5 is not inverse
 //The format of md5 is basically the same
 //When using it, just copy it according to the following format.
 func main() {
     Md5Inst := md5.New()
     Result := Md5Inst.Sum([]byte(""))
     fmt.Printf("%x\n\n", Result)

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/754403

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us


Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top