Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "os"
- "io/ioutil"
- "encoding/json"
- "strconv"
- )
- type DeviceData struct {
- DeviceData []DevicesYo `json:"data"`
- }
- type DevicesYo struct {
- Collector string `json:"collector"`
- Command string `json:"command"`
- cpyKey int `json:"cpyKey"`
- deviceId int `json:"deviceId"`
- fileSize int `json:"fileSize"`
- fileName string `json:"filename"`
- fullPath string `json:"fullPath"`
- rawData string `json:"rawData"`
- }
- func main(){
- jsonFile, err := os.Open("output.json")
- if err != nil {
- fmt.Println(err)
- }
- fmt.Println("Successfully Opened json file yo...")
- defer jsonFile.Close()
- byteValue, _ := ioutil.ReadAll(jsonFile)
- var devs DeviceData
- //var result map[string]interface{}
- json.Unmarshal([]byte(byteValue), &devs)
- //fmt.Println(result["data"]) prints out everything, only for TEsting
- for devices := 0; devices < len(devs.DeviceData); devices++ {
- fmt.Println(devices)
- fmt.Println("---------------------------------")
- fmt.Println("Collector: " + devs.DeviceData[devices].Collector)
- fmt.Println("Command: " + devs.DeviceData[devices].Command)
- fmt.Println("Company Key: " + strconv.Itoa(devs.DeviceData[devices].cpyKey))
- fmt.Println("File Size: " + strconv.Itoa(devs.DeviceData[devices].fileSize))
- fmt.Println("Fullpath: " + devs.DeviceData[devices].fileName)
- fmt.Println("Config Data: " + devs.DeviceData[devices].rawData)
- fmt.Println("---------------------------------")
- fmt.Println("\n")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement