I'm trying to unmarshal a JSON file from Darksky, and as it's fairly complex JSON I've build a struct of sub-structs. A partial example of the structs used is:
type current struct {
Time uint `json:"time"` // 1453402675,
Summary string `json:"summary"` // "Rain",
Icon string `json:"icon"` // "rain",
NearestStormDistance uint `json:"nearestStormDistance"` // 0,
PrecipIntensity float64 `json:"precipIntensity"` // 0.1685,
PrecipIntensityError float64 `json:"precipIntensityError"` // 0.0067,
PrecipProbability float64 `json:"precipProbability"` // 1,
PrecipType string `json:"precipType"` // "rain",
Temperature float64 `json:"temperature"` // 48.71,
ApparentTemperature float64 `json:"apparentTemperature"` // 46.93,
Dewpoint float64 `json:"dewPoint"` // 47.7,
Humidity float64 `json:"humidity"` // 0.96,
WindSpeed float64 `json:"windSpeed"` // 4.64,
WindBearing int `json:"windBearing"` // 186,
Visibility float64 `json:"visibility"` // 4.3,
CloudCover float64 `json:"cloudCover"` // 0.73,
Pressure float64 `json:"pressure"` // 1009.7,
Ozone float64 `json:"ozone"` // 328.35
}
type forecastData struct {
Latitude float64 `json:"latitude"` // 40.47780682531368,
Longitude float64 `json:"longitude"` // -86.93875375799722,
Timezone string `json:"timezone"` // "America/Indiana/Indianapolis",
Current current
Daily daily
Alerts []alert
Offset int `json:"offset"` // -4
}
It unmarshals correctly into the entire structure except for the portion that goes into current. I've played with the types, though a problem with those usually seems to effect only that specific field. I've looked at the declarations and looked at them literally for hours. I've put a complete example on the Go Playground at https://play.golang.org/p/XKaIxfvS8a. At this point, I would appreciate any suggestions. Thanks!
Is this what you expected?
https://play.golang.org/p/NBn0KL8DVw
If so, you forgot to define the json field for Current in this line:
Current current `json:"currently"`