package main
import "fmt"
import "encoding/json"
func main() {
m := make(map[string]string)
m["name"] = "Test"
j, _ := json.Marshal(m)
fmt.Println(string(j))
var unmarshalled map[string]string
_ = json.Unmarshal(j, unmarshalled)
fmt.Println(unmarshalled)
}
不应该使用json数据填充unmarshalled
j
答案 0 :(得分:6)
不要忽视您的错误
json: Unmarshal(non-pointer map[string]string)
unmarshaled
需要成为一个指针:
err := json.Unmarshal(j, &unmarshalled)