I am integrating API and parsing its response in a structure. For this I need to declare field name as type
as API's response contains key
named type
. But when I declare type
in field name it gives me error:
syntax error: unexpected literal
type
, expecting field name or embedded type.
I don't know how to declare literal type
as struct field name.
My struct is
type Test struct {
active bool
name string
description string
amount int
currency string
type string
}
Update your struct to this , to unmarshal api response you need to export your structure's fields i.e your structs feilds should be in upper case:
type Test struct {
Active bool `json:"active"`
Name string `json:"name"`
Description string `json:"description"`
Amount int `json:"amount"`
Currency string `json:"currency"`
Type string `json:"type"`
}
And then try to unmarshal your API response to this struct
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With