JSON Data Response
In GoFrame, you can return JSON data using the following methods:
func (r *Response) WriteJson(content interface{})
func (r *Response) WriteJsonExit(content interface{})
Using these methods will directly convert the provided content into JSON format and send it back to the client. The Content-Type
header in the response will automatically be set to application/json
.
WriteJson(content interface{})
: Writes JSON response without exiting the request flow.WriteJsonExit(content interface{})
: Writes JSON response and immediately exits the request flow.
These methods simplify the process of sending structured data, such as API responses, in JSON format from your GoFrame application to clients.