简体   繁体   English

Golang编码/ JSON马歇尔添加空

[英]Golang encoding/json marshall add null

Hi i am working with golang on encoding/json and it return the json error with null: 嗨,我正在使用golang编码/ json,它返回带有null的json错误:

{"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. 查看您引用的JSON输出,看起来错误已正确编码,但在JSON之后输出null,表明有单独的写操作。 The function that calls EncodeErrorResponse, after it calls it, is writing additional output to the ResponseWriter. 调用EncodeErrorResponse的函数在调用它之后,正在将其他输出写入ResponseWriter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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