Created
August 17, 2019 15:35
-
-
Save voratham/fb935dc770f045eea56ba3155b030d6b to your computer and use it in GitHub Desktop.
map_json.go
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 userAccount struct { | |
| FirstName string `json:"firstName"` | |
| LastName string `json:"lastName"` | |
| } | |
| func main() { | |
| jsonString := `{ "firstName" : "Voratham" , "lastName" :"Siri"}` | |
| fmt.Println(jsonString) | |
| var user1 userAccount | |
| jsonConveter(jsonString, &user1) | |
| fmt.Println("user1 :: ", user1) | |
| } | |
| func jsonConveter(body string, data *userAccount) { | |
| bs := []byte(body) | |
| err := json.Unmarshal(bs, &data) | |
| if err != nil { | |
| fmt.Println("err :: ", err) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment