Guest User

Untitled

a guest
Jan 9th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. )
  7.  
  8. func main() {
  9.  
  10. // Go stores JSON data as an array of bytes.
  11. jstr := `{"fname":"john","lname":"doe","age":25}`
  12. b := []byte(jstr)
  13.  
  14. // In Go, a generic object has type of 'interface{}'
  15. // JSON is either an object of key-value pairs, i.e map[string]interface{}
  16. // ...or an array of objects, i.e []interface{}
  17. var jobj map[string]interface{}
  18.  
  19. // Unmarshalling => decoding JSON to Go object.
  20. if err := json.Unmarshal(b, &jobj); err != nil {
  21. fmt.Println(err.Error())
  22. }
  23.  
  24. fmt.Println(jobj["fname"])
  25. }
Add Comment
Please, Sign In to add comment