我很好奇为什么这个 DeepEqual 检查是错误的:
package main
import (
"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)
}
}
慕村9548890
相关分类