1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| package main
import ( "encoding/json" "fmt" )
func main() { mJson := `{"age":11,"gender":77,"name":"HanMeimei","subject":["语文","数学","英语"]}` m:=make(map[string]interface{}) json.Unmarshal([]byte(mJson),&m) fmt.Println(m)
for key,value := range m{ switch value.(type){ case string: fmt.Printf("m[%s] = %s,type = string\n",key,value) case int: fmt.Printf("m[%s] = %d,type = int\n",key,value) case float64: fmt.Printf("m[%s] = %f,type = float64\n",key,value) case []interface{}: fmt.Printf("m[%s] = %s,type = []interface{}\n",key,value) case byte: fmt.Printf("m[%s] = %s,type = byte\n",key,value) } } }
|