Skip to content

when fields greater than ten,unmarshal fails #250

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

Closed
songhaitao opened this issue Mar 20, 2018 · 0 comments
Closed

when fields greater than ten,unmarshal fails #250

songhaitao opened this issue Mar 20, 2018 · 0 comments

Comments

@songhaitao
Copy link

type S1 struct {
	A string
	B string
	C string
}

type S2 struct {
	A string
	B string
	C string
	D string
	E string
	F string
	G string
	H string
	I string
	J string
	K string
}

func main() {
	var json = jsoniter.ConfigCompatibleWithStandardLibrary
	s1str := `{"a":"1","b":"2","c":"3"}`
	s1 := &S1{}
	json.UnmarshalFromString(s1str, s1)
	fmt.Printf("%+v\n", s1)

	s2str := `{"a":"1","b":"2","c":"3","d":"4","e":"5","f":"6","g":"7","h":"8","i":"9","j":"10","k":"11"}`
	s2 := &S2{}
	json.UnmarshalFromString(s2str, s2)
	fmt.Printf("%+v\n", s2)
}

运行结果:
&{A:1 B:2 C:3}
&{A: B: C: D: E: F: G: H: I: J: K:}

json库版本:1.1.3

虽然可以通过设置属性的TAG来解决,但是感觉解码行为受结构体属性个数影响导致行为不一致有点小坑,所以提出这个ISSUE。

fieldDecoder = decoder.fields[strings.ToLower(field)]

其实这里也尝试了转小写去寻找fieldDecoder,只是场景可能有点多。

@taowen taowen closed this as completed in 06e0f93 Mar 20, 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