Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/json"
- "fmt"
- "strings"
- )
- type Item struct {
- Value *int
- }
- func main() {
- var jsonBlob = `[
- {},
- {"Value": null},
- {"Value": 0},
- {"Value": 1}
- ]`
- var items []Item
- err := json.NewDecoder(strings.NewReader(jsonBlob)).Decode(&items)
- if err != nil {
- fmt.Println("error:", err)
- }
- for _, a := range items {
- if a.Value != nil {
- fmt.Println(*a.Value)
- } else {
- fmt.Println(a.Value)
- }
- }
- }
- <nil>
- <nil>
- 0
- 1
- <nil>
- <error>
- 0
- 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement