Skip to content

Instantly share code, notes, and snippets.

@naoki-sawada
Last active June 15, 2019 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naoki-sawada/e6eca7f2356b8cc836ad2bda2daa7bbd to your computer and use it in GitHub Desktop.
Save naoki-sawada/e6eca7f2356b8cc836ad2bda2daa7bbd to your computer and use it in GitHub Desktop.
json with go
package main
import (
"encoding/json"
"fmt"
)
type response1 struct {
Page int `json:"page"`
Fruits []string `json:"fruits"`
}
func main() {
str := []byte(`{"num":6,"fruits":["a","b"],"hoge":"aaa"}`)
res := response1{}
json.Unmarshal(str, &res)
fmt.Println(res)
fmt.Println(res.Page)
for _, v := range res.Fruits {
fmt.Println(v)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment