查看以下golang代码:
b := []byte(`["a", "b"]`)
var value interface{}
json.Unmarshal(b, &value)
fmt.Println(value) // Print [a b]
fmt.Println(reflect.TypeOf(value)) //Print []interface {}
var targetValue interface{} = []string{"a", "b"}
if reflect.DeepEqual(value.([]interface{}), targetValue) {
t.Error("please be equal")
}
我期待太多的DeepEqual
?阅读文档,以下语句强化了我的假设它应该工作:
我在这里错过了什么?
你将[]interface{}
与[]string
进行比较,if reflect.DeepEqual(value.([]interface{}), targetValue) {
永远不会相等。
targetValue
与[]string
类型的var targetValue interface{} = []string{"a", "c"}
相比:
qazxswpoi