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")
}
}
posted @ 2021-08-25 12:13  技术颜良  阅读(80)  评论(0编辑  收藏  举报