当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS 对象转化为字典

iOS 对象转化为字典

2018年02月08日  | 移动技术网移动技术  | 我要评论

iOS 对象转化为字典,在实际开发的过程中,很多时候我们需要上传数据,代码中我们用对象处理数据,上传我们就需要把对象转化为字典。

//对象转化为字典

-(NSMutableDictionary *)onereturnToDictionaryWithModel:(XXXXX*)model

{

NSMutableDictionary *userDic = [NSMutableDictionary dictionary];

unsigned int count = 0;

objc_property_t *properties = class_copyPropertyList([XXXXXclass], &count);

for (int i = 0; i < count; i++) {

const char *name = property_getName(properties[i]);

NSString *propertyName = [NSString stringWithUTF8String:name];

id propertyValue = [model valueForKey:propertyName];

if (propertyValue) {

[userDic setObject:propertyValue forKey:propertyName];

}

}

free(properties);

return userDic;

}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网