1
0
gotour-notes/readjson/go.go

24 lines
361 B
Go
Raw Normal View History

2012-08-01 08:13:13 -07:00
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)
}