Last active
December 18, 2015 14:08
-
-
Save qsun/5794635 to your computer and use it in GitHub Desktop.
basic usage of json marshal
This file contains hidden or 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" | |
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