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

模型转字典出现问题,模型中属性名变成JSON 中的Key #192

Open
medivh-xiong opened this issue Jan 14, 2017 · 3 comments
Open

Comments

@medivh-xiong
Copy link

我先是使用字典转模型,中间因为模型中的属性名和JSON中的key不一致,进行转化。拿到模型后,再把模型转字典,这时候发现得到的字典里面的属性名变成JSON中的key而不是我模型中正确的属性名。通过断点,发现问题出现在:
- (id)yy_modelToJSONObject { /* Apple said: The top level object is an NSArray or NSDictionary. All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull. All dictionary keys are instances of NSString. Numbers are not NaN or infinity. */ id jsonObject = ModelToJSONObjectRecursive(self); if ([jsonObject isKindOfClass:[NSArray class]]) return jsonObject; if ([jsonObject isKindOfClass:[NSDictionary class]]) return jsonObject; return nil; }
在这个方法中传过去的self中属性名是正确的,在 id jsonObject = ModelToJSONObjectRecursive(self);之后,拿到的jsonObject中属性名就变成了之前JSON中的key值

@miaoruiyuan
Copy link

解决了么

@miaoruiyuan
Copy link

@medivh-xiong

@SamLee123
Copy link

ModelToJSONObjectRecursive 方法里面改一行代码就可以了,1270行
if (!dic[propertyMeta->_name]) {
[dic setValue:value forKey:propertyMeta->_name];
NSLog(@"========%@",dic);

        }

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

3 participants