Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsoniter.RawMessage类型解析的错误 #291

Closed
haishenming opened this issue Jul 10, 2018 · 0 comments
Closed

jsoniter.RawMessage类型解析的错误 #291

haishenming opened this issue Jul 10, 2018 · 0 comments

Comments

@haishenming
Copy link

我创建了一个包含jsoniter.RawMessage类型的结构体,如下

type Log struct {
	Env   string                          `json:"env"`
	Extra jsoniter.RawMessage `json:"extra,omitempty"`
}

然后实例化

log := Log{
		Env: "jfdk",
	}

我并没有给Extra赋值,此时它应该为空,我尝试将此对象解析成json字符串

logString, err := jsoniter.Marshal(log)
fmt.Println(err)
fmt.Println(string(logString))

此时程序没有打印错误,打印出解析后的字符床如下
"{"env":"jfdk","extra":}"
这明显不是一个符合json标准的字符串

然后我尝试将该字符串反解成结构体对象

err = jsoniter.Unmarshal(logString, relog)
fmt.Println(err)
fmt.Println(relog)

此时程序报错了

main.Log.Extra: Skip: do not know how to skip: 125, error found in #10 byte of ...|,"extra":}|..., bigger context ...|{"env":"jfdk","extra":}|...

所以,这是一个bug吗,还是我使用的姿势不对?

@taowen taowen closed this as completed in 5d789e5 Aug 6, 2018
zhenzou pushed a commit to zhenzou/jsoniter that referenced this issue Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant