64 lines
1000 B
Go
64 lines
1000 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
type people struct {
|
||
|
Example int `json:"number"`
|
||
|
personalDetails personalDetails
|
||
|
}
|
||
|
|
||
|
type personalDetails struct {
|
||
|
Name string `json:"name"`
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
query := `
|
||
|
{
|
||
|
"message": "success",
|
||
|
"people": [
|
||
|
{
|
||
|
"name": "Jasmin Moghbeli",
|
||
|
"craft": "ISS"
|
||
|
},
|
||
|
{
|
||
|
"name": "Andreas Mogensen",
|
||
|
"craft": "ISS"
|
||
|
},
|
||
|
{
|
||
|
"name": "Satoshi Furukawa",
|
||
|
"craft": "ISS"
|
||
|
},
|
||
|
{
|
||
|
"name": "Konstantin Borisov",
|
||
|
"craft": "ISS"
|
||
|
},
|
||
|
{
|
||
|
"name": "Oleg Kononenko",
|
||
|
"craft": "ISS"
|
||
|
},
|
||
|
{
|
||
|
"name": "Nikolai Chub",
|
||
|
"craft": "ISS"
|
||
|
},
|
||
|
{
|
||
|
"name": "Loral O'Hara",
|
||
|
"craft": "ISS"
|
||
|
}
|
||
|
],
|
||
|
"number": 7
|
||
|
}`
|
||
|
textBytes := []byte(query)
|
||
|
urbDicRequest := people{}
|
||
|
err := json.Unmarshal(textBytes, &urbDicRequest)
|
||
|
if err != nil {
|
||
|
log.Fatalf("Error happened parsing json: %v\n", err)
|
||
|
}
|
||
|
|
||
|
fmt.Println(urbDicRequest.personalDetails.Name)
|
||
|
|
||
|
}
|