September 2017
Intermediate to advanced
466 pages
9h 33m
English
In this subsection, you will see how to use Marshal() and Unmarshal() in order to implement the functionality of readJSON.go and writeJSON.go. The Go code that illustrates the Marshal() and Unmarshal() functions can be found in marUnmar.go, and this will be presented in four parts.
The first part of marUnmar.go is the expected preamble:
package main
import (
"encoding/json"
"fmt"
"os"
)
type Record struct {
Name string
Surname string
Tel []Telephone
}
type Telephone struct {
Mobile bool
Number string
}
The second part of the program contains the following Go code:
func main() { myRecord := Record{ Name: "Mihalis", Surname: "Tsoukalos", Tel: []Telephone{Telephone{Mobile: true, Number: "1234-567"}, Telephone{Mobile: ...Read now
Unlock full access