Created
March 10, 2016 06:52
-
-
Save xigang/1fec1cbb469065e586c8 to your computer and use it in GitHub Desktop.
将encode编码的数据写入相关联的对象
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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