()
| 15 | ) |
| 16 | |
| 17 | func ExampleMarshal() { |
| 18 | type ColorGroup struct { |
| 19 | ID int |
| 20 | Name string |
| 21 | Colors []string |
| 22 | } |
| 23 | group := ColorGroup{ |
| 24 | ID: 1, |
| 25 | Name: "Reds", |
| 26 | Colors: []string{"Crimson", "Red", "Ruby", "Maroon"}, |
| 27 | } |
| 28 | b, err := json.Marshal(group) |
| 29 | if err != nil { |
| 30 | fmt.Println("error:", err) |
| 31 | } |
| 32 | os.Stdout.Write(b) |
| 33 | // Output: |
| 34 | // {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]} |
| 35 | } |
| 36 | |
| 37 | func ExampleUnmarshal() { |
| 38 | jsonBlob := []byte(`[ |