blob: 1a9b881be07609c9ec40a190a732ae08be04655f [file] [log] [blame]
// +build 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
}
}
}