【发布时间】:2016-10-30 06:20:49
【问题描述】:
我正在尝试解析 this url 中的 json。我的代码如下,但输出不符合预期。我只想为 pushevent 提取有效载荷中的 id、url。我怎么做 。谢谢
type events struct {
id string `json:"id"`
}
func pullUrlFromGit(urlHolder chan string){
client := &http.Client{}
resp, _ := client.Get("https://api.github.com/events")
defer resp.Body.Close()
body,_ := ioutil.ReadAll(resp.Body)
var gtevents []events
json.Unmarshal(body,>events)
log.Printf("%+v",gtevents)
}
我得到的输出如下。
[{id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:} {id:}]
【问题讨论】:
标签: json go unmarshalling