Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/json"
- "fmt"
- "io/ioutil"
- "os"
- )
- type Item struct {
- title string
- description string
- }
- type Column struct {
- items []Item
- }
- type Columns struct {
- columns []Column
- }
- func ReadFile(fileName string) {
- jsonFile, err := os.Open(fileName)
- if err != nil {
- fmt.Println("JSON IO ERROR: " + err.Error())
- }
- fmt.Println("Successfully opened " + fileName)
- defer jsonFile.Close()
- byteValue, _ := ioutil.ReadAll(jsonFile)
- var columns Columns
- // we unmarshal our byteArray which contains our
- // jsonFile's content into 'columns' which we defined above
- json.Unmarshal(byteValue, &columns)
- for i := 0; i < len(columns.columns); i++ {
- for j := 0; j < len(columns.columns[i].items); j++ {
- fmt.Println("Title " + columns.columns[i].items[j].title)
- fmt.Println("Desc " + columns.columns[i].items[j].description)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment