Skip to content

Instantly share code, notes, and snippets.

@qsun
Last active December 18, 2015 14:08
Show Gist options
  • Save qsun/5794635 to your computer and use it in GitHub Desktop.
Save qsun/5794635 to your computer and use it in GitHub Desktop.
basic usage of json marshal
package main
import "encoding/json"
import "fmt"
type FailureMessage struct {
Mail string
To string
Host string
Message string
}
type LolMessage struct {
Host string
Message string
Mail string
To string
}
func main() {
fmt.Println("OK")
m := FailureMessage{"Body", "[email protected]", "qmd1.freelancer.com", "550 error"}
fmt.Println(m)
var m2 LolMessage
info, _ := json.Marshal(m)
fmt.Println(string(info))
err := json.Unmarshal([]byte(string(info)), &m2)
if err != nil {
fmt.Print("Fail")
}
fmt.Print(m2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment