A website for my game dev stuff that supports chat, etc.
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.
 
 
 
 
 
zedshaw-games/scratchpad/json_decode.go

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