Last active
November 14, 2018 08:38
-
-
Save nikita8/77d1ef38b84448e30afe634fe26e9b71 to your computer and use it in GitHub Desktop.
JSON decoding in GO
This file contains 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
// 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