Skip to content

Instantly share code, notes, and snippets.

@johnvilsack
Created June 24, 2014 19:48
Show Gist options
  • Save johnvilsack/9b424aa96675823aede0 to your computer and use it in GitHub Desktop.
Save johnvilsack/9b424aa96675823aede0 to your computer and use it in GitHub Desktop.
getJSON in Go
package main
import (
"encoding/json"
"fmt"
)
type itemResult struct {
Query string `json:"query"`
Count int `json:"count"`
Objects []struct {
ItemID string `json:"ITEM_ID"`
ProdClassID string `json:"PROD_CLASS_ID"`
Available int `json:"AVAILABLE"`
} `json:"objects"`
}
func main() {
payload := []byte(`{"query": "QEACOR139GID","count": 1,"objects": [{"ITEM_ID": "QEACOR139GID","PROD_CLASS_ID": "BMXCPGRIPS","AVAILABLE": 19}]}`)
b := &itemResult{}
err := json.Unmarshal(payload, &b)
if err != nil {
panic(err)
}
fmt.Println(b.Objects[0].ItemID)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment