GO语言中 byte 与map 两种类型的转换
作者:互联网
package main
import (
"encoding/json"
"fmt"
)
func main() {
map2byte2map()
}
func map2byte2map() {
map1 := make(map[string]interface{})
map1["1"] = "hello"
map1["2"] = "world"
// map to []byte
str, err := json.Marshal(map1)
if err != nil {
fmt.Println(err)
}
// byte to map
map2 := make(map[string]interface{})
err = json.Unmarshal(str, &map2)
if err != nil {
fmt.Println(err)
}
fmt.Println("json to map ", map2)
fmt.Println("The value of key1 is", map2["1"])
}
标签:map,err,fmt,map2,Println,json,GO,byte 来源: https://blog.csdn.net/JineD/article/details/121615967