将带有Json数据的字符串传递给Golang中的Map [重复]

This question already has an answer here:

Currently I have stored in my database json objects as string. I want to pass them to a map to be able to consult any field as:

Mymap["Name"]
Mymap["Age"]
..

Let's say that my string would be something like:

'{"Name":["zero"],"Age":"10"}'

I don't know the structure of the data, so that Json can have many fields as required and also many levels of nestings (but I am worried more about to get at least the first level)

</div>

If you're dealing with a json object of arbitrary structure you can use a map of interfaces as the type to unmarshal it into.

map[string]interface{}

The encoding/json package will nicely unmarshal the json object into it, nested or not.

This, while very flexible, has an obvious downside, the types of the map's values are unknown and so to do anything useful with them you'll have to use a type assertion or type switch.

v, ok := m["key"].(Type)

https://play.golang.org/p/wM0gkU1g5G