Skip to content

Instantly share code, notes, and snippets.

@lidaobing
Last active August 29, 2015 14:02
Show Gist options
  • Save lidaobing/dfc26fc414283c364ffe to your computer and use it in GitHub Desktop.
Save lidaobing/dfc26fc414283c364ffe to your computer and use it in GitHub Desktop.
$ go run 13.go
main.A{A:0}
main.A{A:0}
main.A{A:1}
(*main.A)(nil)
(*main.A)(nil)
&main.A{A:1}
package main
import (
"encoding/json"
"fmt"
)
type A struct {
A int
}
func main() {
a := A{}
data1 := []byte("null")
data2, _ := json.Marshal(A{1})
fmt.Printf("%#v\n", a)
json.Unmarshal(data1, &a)
fmt.Printf("%#v\n", a)
json.Unmarshal(data2, &a)
fmt.Printf("%#v\n", a)
b := (*A)(nil)
fmt.Printf("%#v\n", b)
json.Unmarshal(data1, &b)
fmt.Printf("%#v\n", b)
json.Unmarshal(data2, &b)
fmt.Printf("%#v\n", b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment