Created
May 12, 2014 18:07
-
-
Save smagch/1b4d2676cf5f9d4c5068 to your computer and use it in GitHub Desktop.
JSON
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" | |
| "fmt" | |
| ) | |
| type Post struct { | |
| Id int `json:"id"` | |
| UserId int `json:"-"` | |
| Title string `json:"title"` | |
| } | |
| type User struct { | |
| Id int `json:"id"` | |
| Name string `json:"name"` | |
| } | |
| type J struct { | |
| *Post | |
| User *User `json:"user"` | |
| } | |
| func main() { | |
| p := &Post{100, 1, "foobar2000"} | |
| u := &User{1, "tomoya"} | |
| j := &J{p, u} | |
| b, err := json.Marshal(j) | |
| if err != nil { | |
| panic(err) | |
| } | |
| fmt.Println(string(b)) | |
| //fmt.Println("Hello, playground", p, u, j) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment