如何在Go BeeGo框架中传递JSON响应?

I'm building microservices app with go and beego. I'm trying to pass JSON response from service A to service B as following:

func (u *ServiceController) GetAll() {
    req := httplib.Get("http://localhost/api/1/services")
    str, err := req.String()
    // str = {"id":1, "name":"some service"}
    if err != nil {
        fmt.Println(err)
    }
    u.Data["json"] = str
    u.ServeJSON()
}

However, when I send the response I actually double json encoding:

"{\"id\":\"1\",\"name\":\"some service\"}"

Finally, this is the solution I came up with:

func (u *ServiceController) GetAll() {
    req := httplib.Get("http://localhost/api/1/services")
    str, err := req.String()
    if err != nil {
        fmt.Println(err)
    }

    strToByte := []byte(str)
    u.Ctx.Output.Header("Content-Type", "application/json")
    u.Ctx.Output.Body(strToByte)
}

Try this:

func (u *ServiceController) GetAll() {
    req := httplib.Get("http://localhost/api/1/services")
    str, err := req.Bytes()
    // str = {"id":1, "name":"some service"}
    if err != nil {
        fmt.Println(err)
    }
    u.Ctx.Output.Header("Content-Type", "text/plain;charset=UTF-8")
    u.Ctx.ResponseWriter.Write(str)
}

If you call req.String(), it will encode the " in the json string. I suggest you use []byte to handle data usually.