briandowns / openweathermap

Go (golang) package for use with openweathermap.org's API.
Apache License 2.0
240 stars 70 forks source link

Invalid data type of cod and message #71

Open sebastian-garn opened 6 years ago

sebastian-garn commented 6 years ago

Hi,

I am using the 16 days weather forecast but I get the error "json: cannot unmarshal number into Go value of type string". The issue occurs because the struct is defined as:

type Forecast16WeatherData struct {
    COD     int                     `json:"cod"`
    Message string                  `json:"message"`
    City    City                    `json:"city"`
    Cnt     int                     `json:"cnt"`
    List    []Forecast16WeatherList `json:"list"`
}

But the json response looks like:

{
...
"cod":"200",
"message":0.9065923,
...
}

The following solutions fix this issue:

  1. You can either define COD as string and Message as type float64
  2. Comment out both fields

Looking at the examples in docs of OWM the COD should be int. So your model is correct but the actually json response differs...so I would prefer solution 2 until the staff of OWM has fixed it or at least adjust the examples ;)

Btw. solution 2 was already implemented in forecast5.go

apprell commented 4 years ago

Hi, the same problem, why not do it like in forecast5.go by commenting out these lines?