JSON parsing example
This commit is contained in:
parent
e781ac8bb4
commit
9ccf27add8
23
readjson/go.go
Normal file
23
readjson/go.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user