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

🐞 fix: zjson.Unmarshal map data #32

Merged
merged 1 commit into from
Jun 22, 2024
Merged

Conversation

wetor
Copy link
Contributor

@wetor wetor commented Jun 22, 2024

zjson.Unmarshal 在处理如 map[string][]any map[string]int 等value为非any、struct数据时,返回结果为空

原因是此处对 value的类型做了case, 导致value非这三种类型的map均无法正常解析

:1982

	case reflect.Map:
		key := t.Key()
		s := key.Kind() == reflect.String
		if s {
			kind := t.Elem().Kind()
			switch kind {
			case reflect.Interface:
				val.Set(zreflect.ValueOf(jsval.Value()))
			case reflect.Struct, reflect.Ptr:
				v := reflect.MakeMap(t)
				jsval.ForEach(func(key, value *Res) bool {
					newval := reflect.New(t.Elem())
					elem := newval.Elem()
					assign(value, elem, fmap)
					v.SetMapIndex(zreflect.ValueOf(key.Value()), elem)
					return true
				})
				val.Set(v)
			}
		}

修复后将递归的调用assign方法,支持更多的map value类型

Copy link

vercel bot commented Jun 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zlsgo-wnpk ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 22, 2024 4:07am

@sohaha sohaha merged commit 181ab62 into sohaha:master Jun 22, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants