Created
November 3, 2013 09:32
-
-
Save tcnksm/7288045 to your computer and use it in GitHub Desktop.
Parse .json file by Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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