blob: 0e0bf8fa887a5f2276c4aa899b8d69789d082c8a [file] [log] [blame]
// +build ignore,OMIT
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func main() {
resp, err := http.Get("http://reddit.com/r/golang.json")
if err != nil {
log.Fatal(err)
}
if resp.StatusCode != http.StatusOK {
log.Fatal(resp.Status)
}
r := new(Response)
err = json.NewDecoder(resp.Body).Decode(r)
if err != nil {
log.Fatal(err)
}
for _, child := range r.Data.Children {
fmt.Println(child.Data.Title)
}
}
type Item struct {
Title string
URL string
}
type Response struct {
Data struct {
Children []struct {
Data Item
}
}
}