1
0
Fork 0

JSON parsing example

This commit is contained in:
Stephen M. McQuay 2012-08-01 09:13:13 -06:00
parent e781ac8bb4
commit 9ccf27add8
1 changed files with 23 additions and 0 deletions

23
readjson/go.go Normal file
View File

@ -0,0 +1,23 @@
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)
}