Advertisement
Guest User

Untitled

a guest
May 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "os"
  6. "io/ioutil"
  7. "encoding/json"
  8. "strconv"
  9. )
  10.  
  11.  
  12. type DeviceData struct {
  13. DeviceData []DevicesYo `json:"data"`
  14. }
  15.  
  16.  
  17. type DevicesYo struct {
  18. Collector string `json:"collector"`
  19. Command string `json:"command"`
  20. cpyKey int `json:"cpyKey"`
  21. deviceId int `json:"deviceId"`
  22. fileSize int `json:"fileSize"`
  23. fileName string `json:"filename"`
  24. fullPath string `json:"fullPath"`
  25. rawData string `json:"rawData"`
  26. }
  27.  
  28.  
  29. func main(){
  30.  
  31. jsonFile, err := os.Open("output.json")
  32. if err != nil {
  33. fmt.Println(err)
  34. }
  35.  
  36. fmt.Println("Successfully Opened json file yo...")
  37.  
  38. defer jsonFile.Close()
  39. byteValue, _ := ioutil.ReadAll(jsonFile)
  40.  
  41. var devs DeviceData
  42.  
  43. //var result map[string]interface{}
  44.  
  45. json.Unmarshal([]byte(byteValue), &devs)
  46.  
  47. //fmt.Println(result["data"]) prints out everything, only for TEsting
  48.  
  49. for devices := 0; devices < len(devs.DeviceData); devices++ {
  50. fmt.Println(devices)
  51. fmt.Println("---------------------------------")
  52. fmt.Println("Collector: " + devs.DeviceData[devices].Collector)
  53. fmt.Println("Command: " + devs.DeviceData[devices].Command)
  54. fmt.Println("Company Key: " + strconv.Itoa(devs.DeviceData[devices].cpyKey))
  55. fmt.Println("File Size: " + strconv.Itoa(devs.DeviceData[devices].fileSize))
  56. fmt.Println("Fullpath: " + devs.DeviceData[devices].fileName)
  57. fmt.Println("Config Data: " + devs.DeviceData[devices].rawData)
  58. fmt.Println("---------------------------------")
  59. fmt.Println("\n")
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement