package main import ( "encoding/json" "fmt" "reflect" ) type js struct { Name string `json:"name"` Age int `json:"age"` } func stru() string { var j = js{ Name: "zhangsan", Age: 19, } s, _ := json.Marshal(j) return string(s) } func unmap() map[string]interface{} { var type1 map[string]interface{} var map1 = map[string]interface{}{ "Name": "zhangsan", "age": 19, "intro": "hello my name is zhangsan", } json1, err := json.Marshal(map1) err = json.Unmarshal([]byte(string(json1)), &type1) if err != nil { fmt.Println("test json fail: ", err) } return type1 } func unstruct() js { var json1 js j := stru() err := json.Unmarshal([]byte(j), &json1) if err != nil { fmt.Println("test json fail: ", err) } return json1 } func main() { // s := stru() // fmt.Println(s) um := unmap() us := unstruct() fmt.Println("um type is: ", reflect.TypeOf(um)) fmt.Println("us type is: ", reflect.TypeOf(us)) }