mirror of
https://github.com/MADTeacher/go_basics.git
synced 2025-11-23 21:34:47 +02:00
33 lines
643 B
Go
33 lines
643 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type Actor struct {
|
|
// имя поля при сериализации/десериализации
|
|
Name string `json:"name"`
|
|
Age int `json:"age"`
|
|
// имя тега может отличаться от имени поля структуры
|
|
FilmsAmount int `json:"films_amount,omitempty"`
|
|
AboutActor *string `json:",omitempty"`
|
|
}
|
|
|
|
func main() {
|
|
actorJson := map[string]any{}
|
|
|
|
data, err := os.ReadFile("actor.json")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
err = json.Unmarshal(data, &actorJson)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Printf("%+v", actorJson)
|
|
}
|