Created
June 24, 2014 19:48
-
-
Save johnvilsack/9b424aa96675823aede0 to your computer and use it in GitHub Desktop.
getJSON in 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 ( | |
"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