```go
for k, v := range gobook2 {
switch v2 := v.(type) {
case string:
fmt.Println(k, "is string", v2)
case int:
fmt.Println(k, "is int", v2)
case bool:
fmt.Println(k, "is bool", v2)
/*case []interface{}:
fmt.Println(k, "is an arry: ")
for i, iv := range v2 {
fmt.Println(i, iv)
}*/
default:
fmt.Println(k, "is another type not handle yet")
}
}
```
这是结果:
IsPublished is bool true
Price is another type not handle yet
Title is string Golang programming
Authors is another type not handle yet
Publisher is string ituring.com.cn
我想问:v2到底是个什么东西?
v2 就是一个普通变量呀。
每次循环,v2 被赋新值,和普通的赋值没啥两样。
v2 := "string" // string
v2 := 100 // int
v2 := 'C' // char
v2 := true // bool
你纠结啥呢?
#6