24 lines
361 B
Go
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)
|
|
}
|