初级会员
  • 第 8110 位会员
  • hjli1988
  • 2017-04-19 07:18:48
  • Offline
  • 20 1

最近发布的主题

    暂无

最近发布的文章

    暂无

最近分享的资源

    暂无

最近发布的项目

    暂无

最近的评论

  • := 就是定义并赋值的操作了,你前面定义了一个全局变量a就没有使用到了。修改方法:1.注释掉 var a int这一行;2.把a := 0修改成a = 0即可
  • #5 @hjli1988 运行结果: r = %#v {2 false {5 3 0} {{0 0 [{olivere 16 {0 0 [{golang 16 {16}} {elasticsearch 7 {7}}]}} {sandrae 6 {0 0 [{cycling 6 {6}} {sports 6 {6}}]}}]}}}
  • ```go type Mydate struct { Took int32 `json:"took"` Timed_out bool `json:"timed_out"` T_shards struct { Total int32 `json:"total"` Successful int32 `json:"successful"` Failed int32 `json:"failed"` } `json:"_shards"` Aggregations struct { User struct { Doc_count_error_upper_bound int32 `json:"doc_count_error_upper_bound"` Sum_other_doc_count int32 `json:"sum_other_doc_count"` Buckets []Mydate4 `json:"buckets"` } `json:"user"` } `json:"aggregations"` } type Mydate4 struct { Key string `json:"key"` Doc_count int32 `json:"doc_count"` Tags struct { Doc_count_error_upper_bound int32 `json:"doc_count_error_upper_bound"` Sum_other_doc_count int32 `json:"sum_other_doc_count"` Buckets []Mydate6 `json:"buckets"` } `json:"tags"` } type Mydate6 struct { Key string `json:"key"` Doc_count int32 `json:"doc_count"` Ct struct { Value int32 `json:"value"` } `json:"ct"` } var s = `{"took":2,"timed_out":false,"_shards":{"total":5,"successful":3,"failed":0},"hits":{"total":22,"max_score":0,"hits":[]},"aggregations":{"user":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"olivere","doc_count":16,"tags":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"golang","doc_count":16,"ct":{"value":16}},{"key":"elasticsearch","doc_count":7,"ct":{"value":7}}]}},{"key":"sandrae","doc_count":6,"tags":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"cycling","doc_count":6,"ct":{"value":6}},{"key":"sports","doc_count":6,"ct":{"value":6}}]}}]}}}` func main() { var r Mydate if err := json.Unmarshal([]byte(s), &r); err != nil { panic(err) } else { fmt.Println("r = %#v", r) } } ``` 楼主试试,记得把中间我没有加上的hits那段加上