Skip to content

Instantly share code, notes, and snippets.

@rday
Created September 13, 2012 05:45
Show Gist options
  • Save rday/3712141 to your computer and use it in GitHub Desktop.
Save rday/3712141 to your computer and use it in GitHub Desktop.
Json decode
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