简体   繁体   中英

Golang encoding/json marshall add null

Hi i am working with golang on encoding/json and it return the json error with null:

{"user_message":"Can't find any Query with those parameters","application_context":"GroupsRepository.GetGroupsByQuery: ApplicationError: UserMessage - Error querying database for many Groups. ApplicationContext - Groups.GetMany: pq: column \"refill_too_soon_gpi_digits\" does not exist"} null

and the way that i marshall that it is:

func EncodeErrorResponse(w http.ResponseWriter, err error, status int) {
    w.WriteHeader(http.StatusOK)
    w.Header().Set("Content-Type", "application/json")
    json.NewEncoder(w).Encode(err)
}

could someone help me please.

Looking at the JSON output you quoted, it looks like the error is being encoded correctly, but null is being output after the JSON, indicating a separate write operation. The function that calls EncodeErrorResponse, after it calls it, is writing additional output to the ResponseWriter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM