Skip to content

Instantly share code, notes, and snippets.

@cipepser
Created February 12, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cipepser/1c2eef5c84cb1bb2f2ffc568d5d60d31 to your computer and use it in GitHub Desktop.
Save cipepser/1c2eef5c84cb1bb2f2ffc568d5d60d31 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"os"
"bufio"
"io"
)
type Article struct {
Text string `json:"text"`
Title string `json:"title"`
}
func main() {
articles := []Article{}
f, err := os.Open("../data/jawiki-country.json")
defer f.Close()
if err != nil {
panic(err)
}
r := bufio.NewReader(f)
for {
b, err := r.ReadBytes('\n')
if err == io.EOF {
break
}
a := Article{}
json.Unmarshal([]byte(b), &a)
articles = append(articles, a)
}
for _, article := range articles {
if article.Title == "イギリス" {
fmt.Println(article.Text)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment