先谢谢帮忙看帖的大佬!
日志:
// 需要解析的Jason串:
request info:{"serialno":"10001","command":"UserQueryByNATIP","natip":"20.1.18.97","userport":}
// 解析报错,对应下面代码段里面的logger.Error(logserialno, "%s Json UnmarshalError:
QueryByNATIP::reqparse Json UnmarshalError: invalid character '}' looking for beginning of value
代码:
func (requestpkt *QueryByNATIP) reqparse(logserialno string, packetbuf []byte) error {
funcName := "QueryByNATIP::reqparse"
logger.Trace(logserialno, "%s Begin", funcName)
err := json.Unmarshal(packetbuf, &requestpkt)
if err != nil {
logger.Error(logserialno, "%s Json UnmarshalError: %s", funcName, err.Error())
return err
}
求助:解析Jason键值对值为空时报错:Json UnmarshalError: invalid character '}' looking for beginning of value
jimyokl · · 1574 次点击更多评论
谢谢 ququ1002 提供思路。
试了,报这个错
request info:{"serialno":"10001","command":"UserQueryByNATIP","natip":"20.1.18.97","userport":""}
QueryByNATIP::reqparse Json UnmarshalError: json: cannot unmarshal string into Go value of type int
估计是定义问题,还有转换一下空值的定义:
// request packet struct for query by natip and port
type QueryByNATIP struct {
Serialno string `json:"serialno"`
Command string `json:"command"`
Natip string `json:"natip"`
Userport int `json:"userport"`
}
#2