
jsoniter解析json报文报错
在使用jsoniter库解析json报文时,因报文字段类型未与结构体字段类型匹配,导致解析报错。
报文中other字段:
"other": {"a":[1,2]}结构体car中other字段:
type car struct {
other []byte json:"other"
}可见,other字段在报文中类型为json object,而在结构体中定义为[]byte,导致解析失败。
修改后的结构体:
type Car struct {
Other other `json:"other,omitempty"`
}
type other struct {
A []int `json:"a,omitempty"`
}注意:解析报文时,需要将json中的type信息也加入到结构体中。










