我很好奇為什么這個 DeepEqual 檢查是錯誤的:package mainimport ( "encoding/json" "fmt" "log" "reflect" "strings")type Result struct { Topic string `json:"topic,omitempty"` Id int `json:"id,omitempty"`}// Result represents the returned collection from a topic search.type ResultResponse struct { Result []Result `json:"results"`}func main() { want := ResultResponse{ []Result{{Topic: "Clojure", Id: 1000}}, } input := `{"results": [ {"topic": "Clojure", "id": 1000} ]}` p := ResultResponse{} err := json.NewDecoder(strings.NewReader(input)).Decode(&p) if err != nil { panic(err) } fmt.Println(p, want) if !reflect.DeepEqual(input, want) { log.Printf("returned %+v, want %+v", p, want) }}
3 回答

慕村9548890
TA貢獻1884條經驗 獲得超4個贊
我認為這是一個編輯錯誤。我猜你想編碼的是:
"reflect.DeepEqual(p, want)"
但你實際上寫道:
"reflect.DeepEqual(input, want)"
- 3 回答
- 0 關注
- 292 瀏覽
添加回答
舉報
0/150
提交
取消