Posts

Showing posts with the label golang

Json serialize in golang

package  main import  (      "encoding/json"      "fmt" ) type   Message   struct  {     Name  string     Body  string     Time  int64 } func   main () {      m  := Message{ "Alice" ,  "Hello" ,  1294706395881547000 }      b ,  err  := json. Marshal (m)      if  err ==  nil  {          s  :=  string (b)         fmt. Println (s)     } } // {"Name":"Alice","Body":"Hello","Time":1294706395881547000}