接口转换:interface {}是uint64,而不是float32

时间:2018-04-07 23:00:23

标签: go

基本上我有map[interface{}]interface{}并在键下#34; x"值90(我打印确认数据是正确的),但是当我这样做时

mymap["x"].(float32)

我收到错误

interface conversion: interface {} is uint64, not float32

问题是我期望浮点数(从另一个程序的输出产生)。我也尝试了float32(mymap [" x"])但没有成功(也尝试了google与int64的例子没有成功)。

我正在使用 go版本go1.10.1 linux / amd64

1 个答案:

答案 0 :(得分:0)

这是我的脚本:

switch i := x.(type) {
case nil:
    printString("x is nil")                // type of i is type of x (interface{})
case int:
    printInt(i)                            // type of i is int
case float64:
    printFloat64(i)                        // type of i is float64
case func(int) float64:
    printFunction(i)                       // type of i is func(int) float64
case bool, string:
    printString("type is bool or string")  // type of i is type of x (interface{})
default:
    printString("don't know the type")     // type of i is type of x (interface{})
}