func A() string {
type ResponseData struct {
//Not published because it starts with a lowercase letter
name string
value int64
}
var rd []ResponseData
rd = append(rd,ResponseData{
name:"aaa",
value:1
})
resRaw, _ := json.Marshal(rd)
resultJSON := string(resRaw)
return resultJSON
}
The field of ResponseData is not exposed. If you do this, [{}] ← like this will be included in the resultJSON.
func A() string {
type ResponseData struct {
//It is published because the beginning is uppercase
Name string
Value int64
}
var rd []ResponseData
rd = append(rd,ResponseData{
Name:"aaa",
Value:1
})
resRaw, _ := json.Marshal(rd)
resultJSON := string(resRaw)
return resultJSON
}
By doing this, the field of ResponseData is exported, and as a result, the resultJSON will be filled with the value properly.
Recommended Posts