1
0
mirror of https://github.com/MADTeacher/go_basics.git synced 2025-11-23 21:34:47 +02:00
Files
go_basics/part_5/5.3/8.go
2025-06-14 12:40:10 +03:00

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)
}