Last active
June 15, 2019 16:56
-
-
Save naoki-sawada/e6eca7f2356b8cc836ad2bda2daa7bbd to your computer and use it in GitHub Desktop.
json with go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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