github.com/giovannyortegon/go@v0.0.0-20220115155912-8890063f5bdd/src/BlackHatGo/Chap02/HandlingStructuredData.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	_ "encoding/json"
     6  	"encoding/xml"
     7  )
     8  /*
     9  // json
    10  type Foo struct {
    11  	Bar string
    12  	Baz string
    13  }
    14  */
    15  // xml
    16  type Foo struct {
    17  	Bar string	`xml: "id, attr"`
    18  	Baz string	`xml: "parent>child"`
    19  }
    20  
    21  
    22  func main() {
    23  
    24  	f := Foo {"Joe Junior", "Hello Shabado"}
    25  //	b, _ := json.Marshal(f)
    26  	b, _ := xml.Marshal(f)
    27  	fmt.Println(string(b))
    28  //	json.Unmarshal(b, &f)
    29  	xml.Unmarshal(b, &f)
    30  }