Skip to content

Instantly share code, notes, and snippets.

@nikita8
Last active November 14, 2018 08:38
Show Gist options
  • Save nikita8/77d1ef38b84448e30afe634fe26e9b71 to your computer and use it in GitHub Desktop.
Save nikita8/77d1ef38b84448e30afe634fe26e9b71 to your computer and use it in GitHub Desktop.
JSON decoding in GO
// Go
package main
import (
"encoding/json"
"fmt"
)
// Go
type response struct {
Page int `json:"page"`
Fruits []string `json:"fruits"`
}
func main() {
str := `{"page": 1, "fruits": ["apple", "peach"]}`
res := response{}
json.Unmarshal([]byte(str), &res)
fmt.Println(res.Page)
//=> 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment