ios 自定义对象转json
2016-05-11 本文已影响0人
消魂泪
我想说:切换成markdown模式的时候保存按钮被挡住了。。导致半天也没闹明白为啥没生效!!!
+(NSDictionary *)getObjectData:(id)obj {
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
unsigned int propsCount;
objc_property_t *props = class_copyPropertyList([obj class], &propsCount);
for(int i = 0;i < propsCount; i++){
objc_property_t prop = props[i];
NSString *propName = [NSString stringWithUTF8String:property_getName(prop)];
id value = [obj valueForKey:propName];
if(value == nil){
value = [NSNull null];
}else{
value = [self getObjectInternal:value];
}
[dic setObject:value forKey:propName];
}
return dic;
}
苍天啊!!这个代码框终于出来了!!