Skip to content

Invalid data type of cod and message #71

@sebastian-garn

Description

@sebastian-garn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions