1
0
gotour-notes/readjson/go.go
2012-08-01 09:13:13 -06:00

24 lines
361 B
Go

package main
import (
"encoding/json"
"fmt"
"log"
)
type Person struct {
Name string
Age int
}
func main() {
p := Person{"stephen m mcquay", 31}
b, err := json.Marshal(p)
if err != nil {
log.Fatal(err)
}
var q Person
err = json.Unmarshal(b, &q)
fmt.Printf("before: %v\njson: %s\nafter: %v", p, b, q)
}