Created
April 28, 2018 21:30
-
-
Save laidback/4394b2ac753957e81a44460542e3046f to your computer and use it in GitHub Desktop.
go-json created by laidback - https://repl.it/@laidback/go-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 resp struct { | |
| Fname string `json:"fname, string"` | |
| } | |
| func main() { | |
| // go struct | |
| r := &resp{Fname: "lukas"} | |
| fmt.Printf("%T, %s\n", r, r) | |
| // marshalling to []byte | |
| m, _ := json.Marshal(r) | |
| fmt.Printf("%T, %s, %x\n", m, m, m) | |
| // json string | |
| str := `{"fname": "lukas"}` | |
| pers := &resp{} | |
| // unmarshal json string | |
| if err := json.Unmarshal([]byte(str), &pers); err != nil { | |
| fmt.Println(err) | |
| } | |
| fmt.Printf("%T, %s\n", pers, pers) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment