例如以下图:
从user_logs表格select出来的数据放在一个可变数组NSMutableArray中,如 user_logs,如今要
把数据一条条转化为Userlog databean,UserLog定义例如以下:@interface UserLog : NSObject @property(strong,nonatomic) NSString * logId; @property(strong,nonatomic) NSString * userId; @property(strong,nonatomic) NSString * actionType; @property(strong,nonatomic) NSDate * actionDate; @property(strong,nonatomic) NSString * accountNumber; @property(strong,nonatomic) NSString * dataRef1; @property(strong,nonatomic) NSString * dataRef2; @property(strong,nonatomic) NSString * dataRef3; @property(nonatomic) BOOL uploaded; @property(nonatomic) NSInteger udts; @property(strong,nonatomic) NSString * logType; - (NSDictionary *)convertToDictionary; @end
转化方法例如以下:
-(NSDictionary *)convertUserLogsPropertyToDictionary:(NSMutableArray *)userLogs{ NSMutableArray *userLogsMutableArray = [NSMutableArray array]; for (int i = 0;i< [userLogs count];i++) { UserLog *userLog = userLogs[i]; [userLogsMutableArray addObject:[userLog convertToDictionary]]; } NSDictionary *userLogsDictionary = @{@"objects":userLogsMutableArray}; return userLogsDictionary; }
注意:上面databean的属性并没有与user_logs表中的字段名同样。转化过来的字典会是nil。,
,我这边是已经在其它地方将数据表的字段名转化味驼峰式命名方式的。