Skip to content

Instantly share code, notes, and snippets.

@xigang
Created March 10, 2016 06:52
Show Gist options
  • Save xigang/1fec1cbb469065e586c8 to your computer and use it in GitHub Desktop.
Save xigang/1fec1cbb469065e586c8 to your computer and use it in GitHub Desktop.
将encode编码的数据写入相关联的对象
package main
import (
"encoding/json"
"fmt"
"os"
)
type ColorGroup struct {
ID int
Name string
Colors []string
}
func main() {
group := ColorGroup{
ID: 1,
Name: "redis",
Colors: []string{"Cirmson", "Red", "Ruby"},
}
encoder := json.NewEncoder(os.Stdout)
if err := encoder.Encode(group); err != nil {
fmt.Printf("failed encoding to writer: %s", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment