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

相关文章:

  • 2021-06-13
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2021-06-08
  • 2021-08-15
猜你喜欢
  • 2021-06-15
  • 2021-09-13
  • 2022-01-16
  • 2021-12-15
  • 2021-06-18
  • 2021-08-14
  • 2021-10-16
相关资源
相似解决方案