Created
March 24, 2012 22:25
-
-
Save bradclawsie/2188608 to your computer and use it in GitHub Desktop.
match Go type to 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
#!/usr/bin/env gorun | |
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
type MyJSONType struct { | |
A int | |
B string | |
} | |
func main() { | |
s := "{\"A\":123,\"B\":\"hello\"}" | |
var mjt MyJSONType | |
um_err := json.Unmarshal([]byte(s),&mjt) | |
if um_err == nil { | |
fmt.Printf("%v\n",mjt) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment