go json 反解析接口

b:= []byte(`{"Test":"cheyunhua","Age",19,"Inst":["name","age"]}`)

var f interface{}

err = json.Unmarshal(b,&f)
f = map[string]interface{}{
"Name": "Wednesday",
"Age": 6,
"Parents": []interface{}{
"Gomez",
"Morticia",
},
}

m:=f.(map[string]interface{})
for k, v := range m {
switch vv := v.(type) {
case string:
fmt.Println(k, "is string", vv)
case int:
fmt.Println(k, "is int", vv)
case []interface{}:
fmt.Println(k, "is an array:")
for i, u := range vv {
fmt.Println(i, u)
}
default:
fmt.Println(k, "is of a type I don't know how to handle")
}
}
原文地址:https://www.cnblogs.com/cheyunhua/p/15184488.html