I have a lengthy struct of json key value pairs returned from a GET function. Similiar to:
type content struct {
field1 string `json:"Language"`
field2 int `json:"Runtime"`
field3 time.Time `json:"StartTime"`
field4 time.Time `json:"EndTime"`
field5 int64 `json:"ProgramId`
field6 string `json:"ProviderId"`
field7 string `json:"Title:`
}
I know how to return a single field value using:
println(content.field1)
but how do I return every field name and value without listing out every element? How would I return something like this?
field1:value
Because the JSON decoder ignores unexported field names, you must export the field names:
type content struct {
Field1 string `json:"Language"`
Field2 int `json:"Runtime"`
Field3 time.Time `json:"StartTime"`
Field4 time.Time `json:"EndTime"`
Field5 int64 `json:"ProgramId`
Field6 string `json:"ProviderId"`
Field7 string `json:"Title:`
}
To show the fields, print the decoded value content
using "%+v":
fmt.Printf("%+v
", content)