Advertisement
Guest User

Untitled

a guest
May 20th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. )
  7.  
  8. type Result struct {
  9. Data string
  10. TimeStamp int64
  11. }
  12.  
  13. type ReturnedValue struct {
  14. Result Result
  15. Status bool
  16. }
  17.  
  18. func main() {
  19. data := `
  20. {
  21. "result": {
  22. "data": "A0000",
  23. "timestamp": 9002
  24. },
  25. "status": true
  26. }
  27. `
  28.  
  29. var retValue ReturnedValue
  30. if err := json.Unmarshal([]byte(data), &retValue); err != nil {
  31. panic(err)
  32. }
  33. fmt.Println(retValue)
  34. status := retValue.Status
  35. fmt.Println("Result:", retValue.Result.Data, ", TS:", retValue.Result.TimeStamp, ", Status:", status)
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement