I'm attempting to use the USDA's Farmers Market Directory API to receive a data about where nearby farmer's markets are located, using a zip code. I store the unmarshalled body of the response in:
type marketResponse struct {
MapsLink string `json:"GoogleLink"`
Address string `json:"Address"`
Schedule string `json:"Schedule"`
Products string `json:"Products"`
}
Using the code:
//TODO: location: "http://search.ams.usda.gov/farmersmarkets/v1/data.svc/locSearch?lat=" + lat + "&lng=" + lng
resp, err := http.Get("http://search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=" + zipcode)
if err != nil {
log.Printf("Could net search zipcode %s: %v", zipcode, err)
}
defer func() {
if err := resp.Body.Close(); err != nil {
log.Println(err)
}
}()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println(err)
}
newMarket := &marketResponse{}
if err := json.Unmarshal(body, newMarket); err != nil {
log.Println(err)
}
log.Println("response: " + newMarket.Address)
The problem is, the response body is in JSONp, and I'm unmarshalling in JSON. How can I unmarshal in JSONp, using an external package, or not?