Skip to content

Instantly share code, notes, and snippets.

@bradclawsie
Created March 24, 2012 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradclawsie/2188608 to your computer and use it in GitHub Desktop.
Save bradclawsie/2188608 to your computer and use it in GitHub Desktop.
match Go type to json
#!/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