you can override json format string in new type. this is a small demonstration
package main
import (
"encoding/json"
"fmt"
)
type JSONString string
func (j JSONString) MarshalJSON() ([]byte, error) {
return []byte(j), nil
}
func main() {
s := `{"key1":0,"key2":0}`
content, _ := json.Marshal(JSONString(s))
fmt.Println(_, string(content))
}
in your case you can write like this
this.Data["json"] = JSONString(dao.EventsByTimeRange(request))
this.ServeJson()
BTW, the golang-json package adds quotes because it treats your string as a json value, not a json kv object.
source
share