Guest User

Untitled

a guest
Oct 8th, 2022
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. )
  9.  
  10. type Item struct {
  11. title string
  12. description string
  13. }
  14.  
  15. type Column struct {
  16. items []Item
  17. }
  18.  
  19. type Columns struct {
  20. columns []Column
  21. }
  22.  
  23. func ReadFile(fileName string) {
  24.  
  25. jsonFile, err := os.Open(fileName)
  26.  
  27. if err != nil {
  28. fmt.Println("JSON IO ERROR: " + err.Error())
  29. }
  30.  
  31. fmt.Println("Successfully opened " + fileName)
  32.  
  33. defer jsonFile.Close()
  34.  
  35. byteValue, _ := ioutil.ReadAll(jsonFile)
  36.  
  37. var columns Columns
  38.  
  39. // we unmarshal our byteArray which contains our
  40. // jsonFile's content into 'columns' which we defined above
  41. json.Unmarshal(byteValue, &columns)
  42.  
  43. for i := 0; i < len(columns.columns); i++ {
  44. for j := 0; j < len(columns.columns[i].items); j++ {
  45. fmt.Println("Title " + columns.columns[i].items[j].title)
  46. fmt.Println("Desc " + columns.columns[i].items[j].description)
  47. }
  48. }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment