'Golang - Cannot unmarshal number into Go value of type string
When trying to json.Unmarshal some JSON code from a website into a struct I created, I receive the following error:
cannot unmarshal number into Go value of type string
Here is my code: https://play.golang.org/p/-5nphV9vPw
Solution 1:[1]
There are multiple errors in the struct definition. Here is fixed version.
Solution 2:[2]
Basically, there are some problems with the structs; One might want to use JSON-to-Go
There is a particular problem, I encountered is something like this:
json: cannot unmarshal number into Go struct field
idof type string
Which means Go can't marshal a JSON number, like "id": 35, into a Go string property
- it's either
idbecomes a string"id": "35"; or - change the
idtype in to an int type
type movie struct {
Genres []struct {
Id int
Name string
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CrazyCrow |
| Solution 2 | go je jo |
