go JSON

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

原文地址:https://www.cnblogs.com/allenhaozi/p/5802934.html