This is a creation in Article, where the information may have evolved or changed.
package mainimport ("Encoding/json" "FMT" "OS") type configstruct struct {host string ' JSON: ' Host "' port int ' JSON: ' Port ' ' analyticsfile string ' JSON: "Analytics_file" ' staticfileversion int ' JSON: "Static_file_version" staticdir string ' JSON: ' Static_dir ' templatesdir string ' JSON: "Templates_dir" ' SerTcpSocketHost string ' JSON: "Sertcpsockethost" ' sertcpsocketport int ' JSON: "Sertcpsocketport" ' fruits []string&nbsP; ' JSON: "Fruits" '}type other struct {sertcpsockethost string ' JSON: " Sertcpsockethost "' sertcpsocketport int ' JSON:" SerTcpSocketPort "' Fruits []string ' JSON: "Fruits" '}func main () {jsonStr := ' {"host": "http://localhost:9090", "Port": 9090, "Analytics_file": "", "static_file_version": 1, "Static_dir": "e:/project/gotest/src/", "Templates_dir": "E:/Project /gotest/src/templates/"," Sertcpsockethost ": ": 12340 "," Sertcpsocketport ": 12340," fruits ": [" Apple ", " Peach "]} '//json str turn mapvar dat map[string]interface{}if err := json. Unmarshal ([]byte (JSONSTR), &dat); err == nil {fmt. Println ("==============json str turn map=======================") fmt. PRINTLN (DAT) fmt. Println (dat["host"])}//json str turn Structvar conFig configstructif err := json. Unmarshal ([]byte (JSONSTR), &config); err == nil {fmt. Println ("================json str turn struct==") fmt. Println (config) fmt. Println (config. Host)}//json str to struct (partial field) Var part otherif err := json. Unmarshal ([]byte (JSONSTR), &part); err == nil {fmt. Println ("================json str turn struct==") fmt. Println (part) FMT. Println (part. Sertcpsocketport)}//struct to Json strif b, err := json. Marshal (config); err == nil {fmt. Println ("================struct to json str==") fmt. Println (string (b))}//map to Json strfmt. Println ("================map to json str=====================") Enc := json. Newencoder (OS. Stdout) Enc. Encode (DAT)//array to json strarr := []string{"Hello", "apple", "Python", "Golang", "base", "Peach", "Pear"}lang, err := json. Marshal (arr) if err == nil {fmt. Println ("================array to json str==") fmt. Println (String (lang))}//json to []stringvar wo []stringif err := json. Unmarshal (LANG, &WO); err == nil {fmt. Println ("================json to []string==") fmt. Println (wo)}}