Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/json"
- "fmt"
- )
- func main() {
- // Go stores JSON data as an array of bytes.
- jstr := `{"fname":"john","lname":"doe","age":25}`
- b := []byte(jstr)
- // In Go, a generic object has type of 'interface{}'
- // JSON is either an object of key-value pairs, i.e map[string]interface{}
- // ...or an array of objects, i.e []interface{}
- var jobj map[string]interface{}
- // Unmarshalling => decoding JSON to Go object.
- if err := json.Unmarshal(b, &jobj); err != nil {
- fmt.Println(err.Error())
- }
- fmt.Println(jobj["fname"])
- }
Add Comment
Please, Sign In to add comment