ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
map转json ~~~ package main import ( "encoding/json" "fmt" ) type User struct { UserName string `json:"username"` NickName string `json:"nickname"` Age int Birthday string Sex string Email string Phone string } /*map转json*/ func testMap() { var mmp map[string]interface{} mmp = make(map[string]interface{}) mmp["username"] = "Murphy" mmp["age"] = 19 mmp["sex"] = "man" data, err := json.Marshal(mmp) if err != nil { fmt.Println("json marshal failed,err:", err) return } fmt.Printf("%s\n", string(data)) } func main() { testMap() fmt.Println("----") } ~~~ 输出结果: ~~~ {"age":19,"sex":"man","username":"Murphy"} ---- ~~~