11. Encoding and Decoding (JSON)
Activity 11.01: Mimicking a Customer Order Using JSON
Solution:
All directories and files created need to be created within your $GOPATH
:
- Create a directory called
Activity11.01
within a directory calledChapter11
. - Create a file called
main.go
insideChapter11/Activity11.01
. - Using Visual Studio Code, open the newly created
main.go
file. - Add the following package name and import statements:
package main import ( "encoding/json" "fmt" "os" )
- Add the following
customer
struct
with the JSON tags set accordingly:type customer struct { UserName string `json:"username"` Password string `json:"-"` Token string `json:"-"` ShipTo address `json:"shipto"` PurchaseOrder order `json:"order"` }
- Add the following
order
struct
with...