openweathermap icon indicating copy to clipboard operation
openweathermap copied to clipboard

Invalid data type of cod and message

Open sebastian-garn opened this issue 6 years ago • 1 comments

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

sebastian-garn avatar Sep 13 '18 11:09 sebastian-garn

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

apprell avatar Oct 19 '20 21:10 apprell