This is a created article in which the information may have evolved or changed.
Package Mainimport ("Encoding/json" "FMT") var (str string = ' {"name": "ABC", "Age": 12} ')//the struct to be converted to a JSON string, The first letter of the member variable must be capitalized so that the output JSON string is also uppercase type User struct {name string ' JSON: ' name '//If you want to use the first letter of the key name in JSON text without uppercase, you can add this string to describe the age inttime Int}func Main () {var u useru.name = "abc" U.age = 12b, E: = json. Marshal (u) if E! = nil {fmt. Println (e) return}fmt. Println (string (b))//Converts the user struct to a JSON string, and then outputs//the string below is converted to Structvar tmp usere = json. Unmarshal ([]byte (str), &tmp) if E! = nil {fmt. Println (e)} else {fmt. PRINTLN (TMP)}//fmt. PRINTLN (U)}