私信  •  关注

poy

poy 最近创建的主题
poy 最近回复了
5 年前
回复了 poy 创建的主题 » Golang Redis:地图和切片

你需要转换 Filters 类型 interface{} 到预期的切片中。如果你不知道它是什么类型,你可以用 map[string]interface{} . 因此改变你的 过滤器 类型到 映射[字符串]接口 .

更多信息 如果 过滤器 可以是一个数组(或者不是),那么您可以考虑 type switch :

一个简单的例子:

package main

import (
    "encoding/json"
    "fmt"
)

func main() {
    var i interface{}
    //json.Unmarshal([]byte(`["hi"]`), &i)
    json.Unmarshal([]byte(`{"a":"hi"}`), &i)

    switch i.(type) {
    case []interface{}:
        println("ARRAY")
    case map[string]interface{}:
        println("NOT ARRAY")
    default:
        fmt.Printf("%T\n", i)
    }
}