package utils import ( "encoding/json" "errors" ) func JsonToMap(text []byte) (map[string]interface{}, error) { var anonymous interface{} err := json.Unmarshal(text, &anonymous) if err != nil { return nil, errors.New(err.Error()) } res := anonymous.(map[string]interface{}) return res, nil }
参考:https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/07.2.md
有疑问加站长微信联系(非本文作者)