Created
September 13, 2012 05:45
-
-
Save rday/3712141 to your computer and use it in GitHub Desktop.
Json decode
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" | |
import "net/http" | |
import "bytes" | |
type Test struct{ | |
Name string | |
Token string | |
} | |
func main() { | |
j, _ := json.Marshal(Test{"user","user/001"}) | |
req, _ := http.NewRequest("post", "http://localhost/save?listToken=blog", bytes.NewBuffer(j)) | |
fmt.Println(req.Body) | |
var m Test | |
d := json.NewDecoder(req.Body) | |
d.Decode(&m) | |
fmt.Println(m) | |
fmt.Printf("%s %s\n", m.Name, m.Token) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment