You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
435 B
28 lines
435 B
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type User struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
PhoneNumber string `json:"phoneNumber"`
|
|
}
|
|
|
|
func main() {
|
|
b, err := os.ReadFile("user.json")
|
|
if err != nil {
|
|
log.Fatalf("Failed to read file: %v\n", err);
|
|
}
|
|
|
|
var u User
|
|
json.NewDecoder(bytes.NewBuffer(b)).Decode(&u)
|
|
|
|
fmt.Printf("%#v", u)
|
|
}
|
|
|