Golang编码/json添加空

Golang编码/json添加空,json,go,encoding,Json,Go,Encoding,您好,我正在与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. ApplicationContex

您好,我正在与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
我认为这是:

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)
}

谁能帮帮我吗

查看您引用的JSON输出,看起来错误编码正确,但JSON后面的输出为null,表示单独的写入操作。调用EncodeErrorResponse的函数在调用它之后,正在向ResponseWriter写入额外的输出。

查看您引用的JSON输出,看起来错误编码正确,但
null
在JSON之后输出,这表示单独的写入操作。是否可能有其他代码(可能是此函数的调用方)正在编写此输出?还要注意的是,您输入了一个状态代码,但没有使用它,而是始终使用StatusOK;您忽略了由
Encode
返回的错误。我在另一个函数中使用的函数,但是Encode返回为null的错误,我不知道编码/json是否有问题,因为在另一个结构中它工作正常。编码/json没有问题。调用
EncodeErrorResponse
的函数在调用它之后,正在向
ResponseWriter
写入额外的输出。是的,这是代码上的一个错误,在它写入错误之后,我写入一个空值,谢谢!作为答复转载。