我正在編寫一個 JSON 列表為空的測試。{"matches": []}該對象具有 type map[string]interface{},我想測試該列表是否為空。var matches := response["matches"]if len(matches) != 0 { t.Errorf("Non-empty match list!")}但是我在編譯時被告知這是無效的invalid argument matches (type interface {}) for len如果我嘗試轉換為列表類型:matches := response["matches"].([]string)我感到恐慌:panic: interface conversion: interface is []interface {}, not []string [recovered]我想在這里寫什么?
- 2 回答
- 0 關注
- 235 瀏覽
添加回答
舉報
0/150
提交
取消