我必须在 ELK 的 echo 框架中间件中解组 Json(请求,响应主体),就像这段代码一样。
var reqJSONBody, resJSONBody map[string]interface{}
if len(*reqBody) > 0 {
if err := unmarshalJSON(reqBody, &reqJSONBody); err != nil {
gl.ServiceLogger.Error("error parsing the request body: ", requestURI, err)
}
encryptPrivacyField(&reqJSONBody)
}
if len(*resBody) > 0 && resContentType != "" && strings.Contains(resContentType, "application/json") {
if err := unmarshalJSON(resBody, &resJSONBody); err != nil {
gl.ServiceLogger.Error("error parsing the response body: ", requestURI, err)
}
encryptPrivacyField(&resJSONBody)
}
这是工作,
但是,某些 URI 响应[]map[string]interface{}类型。
所以我得到了这个错误。
json: cannot unmarshal array into Go value of type map[string]interface {}
解决问题的最佳方法是什么?
墨色风雨
相关分类