Created
October 5, 2014 17:07
-
-
Save geraldstanje/cfaf6919ccae6fbf2744 to your computer and use it in GitHub Desktop.
golang json encoding
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" | |
import "fmt" | |
import "bytes" | |
type tableEntry struct { | |
Name string | |
Age string | |
Gender string | |
} | |
func main() { | |
t := tableEntry{"Person", "10", "Male"} | |
jsonData, err := json.Marshal(t) | |
if err != nil { | |
fmt.Println("json encoding error") | |
} | |
var b bytes.Buffer | |
b.Write(jsonData) | |
fmt.Print(b.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment