[{
"id": "114194",
"bt": "标题1",
"fbsj": "2018/11/12",
}, {
"id": "114256",
"bt": "标题1",
"fbsj": "2018/11/16",
}]
怎么将这个数据 转为数组或者map
![image.png](https://static.studygolang.com/181212/3348baddfc517d9cc6816675ead28b9c.png)
#1
更多评论
![WX20181213-103055@2x.png](https://static.studygolang.com/181213/af40f7d4c4b956653d5cf6c107e19560.png)
#2
```
// Json 字符串对象转map
func Jsonstr2map(jsonstr []byte) (map[string]interface{}, error) {
var result map[string]interface{}
if err := json.Unmarshal(jsonstr, &result); err != nil {
return nil, err
}
return result, nil
}
// Json对象转map
func Obj2map(obj interface{}) (map[string]interface{}, error) {
jsonStr, err := json.Marshal(obj) //先转成字符串再转成map
if err != nil {
return nil, err
}
return Jsonstr2map(jsonStr)
}
// map 对象转 string
func Map2JsonStr(obj map[string]interface{}) (string, error) {
json, err := json.Marshal(obj)
if err != nil {
return "", err
}
return string(json), nil
}
```
##### map转结构体的包,里面自带的test用法讲解很详细
传送门:https://github.com/goinggo/mapstructure
#3