Skip to content

Instantly share code, notes, and snippets.

@tcnksm
Created November 3, 2013 09:32
Show Gist options
  • Save tcnksm/7288045 to your computer and use it in GitHub Desktop.
Save tcnksm/7288045 to your computer and use it in GitHub Desktop.
Parse .json file by Go
package main
import (
"encoding/json"
"fmt"
"strings"
)
const blob = `[
{"Title":"0redev", "URL": "http//oredev.org"},
{"Title":"Strange Loop", "URL": "http//thestrangeloop.com"}
]`
type Item struct {
Title string
URL string
}
func main() {
var items []*Item
json.NewDecoder(strings.NewReader(blob)).Decode(&items)
for _, item := range items {
fmt.Printf("Tile: %vm URL: %v\n", item.Title, item.URL)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment