Created
October 13, 2014 09:08
-
-
Save slawosz/a07ffe79c852fe1a12a6 to your computer and use it in GitHub Desktop.
some go
This file contains 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 "fmt" | |
import "encoding/json" | |
type Foo struct { | |
Foo string | |
Body interface{} | |
} | |
var jsonBody = ` | |
{ | |
"Foo": "bar", | |
"Body": { | |
"header": "value" | |
} | |
} | |
` | |
func main() { | |
foo := &Foo{} | |
err := json.Unmarshal([]byte(jsonBody), foo) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
fmt.Println(foo) | |
bar, err := json.Marshal(foo.Body) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
fmt.Println(string(bar)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment