frrostbitee

readJson

Jan 6th, 2021 (edited)
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.60 KB | None | 0 0
  1. type State struct{
  2.     round       []int
  3.     p1val       []int
  4.     p2val       []int
  5.     decided     []int
  6.     decision    []bool
  7.  
  8. }
  9.  
  10. func readJson(filename string) {
  11.     var (
  12.         idState map[string]interface{}
  13.     )
  14.  
  15.     jsonFile, err := os.Open(filename)
  16.  
  17.     if err != nil {
  18.         fmt.Print(err)
  19.     }
  20.  
  21.     fmt.Println("Opened up the file")
  22.  
  23.     bytes, _ := ioutil.ReadAll(jsonFile)
  24.  
  25.     json.Unmarshal([]byte(bytes), &idState)
  26.  
  27.     for key, value := range idState{
  28.         fmt.Println(key, value)
  29.         break
  30.     }
  31.  
  32.     var states State
  33.     for _, value := range idState{
  34.         err = mapstructure.Decode(value, states)
  35.         break
  36.     }
  37.     fmt.Printf("%#v", states)
  38. }
  39.  
Add Comment
Please, Sign In to add comment