package main
import (
"fmt"
"encoding/json"
)
type Department struct {
Id int
Name string
Phone string
}
func main() {
a := Department {1, "test", "12-32"}
fmt.Println(a)
b, _ := json.Marshal(a)
fmt.Println(string(b))
}
{1 test 12-32}
{"Id":1,"Name":"test","Phone":"12-32"}
package main
import (
"fmt"
"encoding/json"
)
type Department struct {
Id int
name string
Phone string
}
func main() {
a := Department {1, "test", "12-32"}
fmt.Println(a)
b, _ := json.Marshal(a)
fmt.Println(string(b))
}
{1 test 12-32}
{"Id":1,"Phone":"12-32"}
type Department struct {
Id int `json:"id"`
Name string `json:"name"`
Phone string `json:"phone"`
}
type Department struct {
Id int `json:"id"`
Name string `json:"name"`
Phone string
AnyField string `json:"part"`
}
{id: 123, name: "Имя", Phone: "123", part: "AnyField"}