Created
January 3, 2018 06:16
-
-
Save eyeezzi/169538060f96a33a3cc0a50ecc912a3b to your computer and use it in GitHub Desktop.
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 User struct { | |
Fname string | |
Mname *string | |
Lname string | |
} | |
func main() { | |
jstr := `{"fname":"john","mname":null,"lname":"doe"}` | |
b := []byte(jstr) | |
var u User | |
if err := json.Unmarshal(b, &u); err != nil { | |
fmt.Println(err.Error()) | |
} | |
fmt.Println(u) | |
res, err := json.Marshal(u) | |
if err != nil { | |
fmt.Println(err.Error()) | |
} | |
fmt.Println(string(res)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment