iOS- 模型映射
+ (StoreInfo *)parseEntityWithDictionary:(NSDictionary *)arributeDict { StoreInfo * instance = [[StoreInfo alloc] init]; for(int i = 0 ; i < [arributeDict count] ; i++) { NSString * attributeStr = [[arributeDict allKeys] objectAtIndex:i]; NSString * tempMethodStr=nil; NSString * firstLetter=[[attributeStr substringToIndex:1] uppercaseString]; tempMethodStr=[attributeStr stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstLetter]; SEL performedSelector; if ([[arributeDict objectForKey:attributeStr] isKindOfClass:[NSString class]]) { performedSelector = NSSelectorFromString([NSString stringWithFormat:@"setM_str%@:",tempMethodStr]); } if ([[arributeDict objectForKey:attributeStr] isKindOfClass:[NSArray class]]) { performedSelector = NSSelectorFromString([NSString stringWithFormat:@"setM_arr%@:",tempMethodStr]); } if ([instance respondsToSelector:performedSelector]) { NSMethodSignature * methodSignature = [[instance class] instanceMethodSignatureForSelector:performedSelector]; NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; [invocation setTarget:instance]; [invocation setSelector:performedSelector]; NSObject * argument = [arributeDict objectForKey:attributeStr]; [invocation setArgument:&argument atIndex:2]; [invocation invoke]; } } return instance; }
数据
"address_s"="上海市黄浦区西藏中路555号";
"area_s"="卢湾区";
businesshours="06:00-11:00";
condition="无线上网 停车场 ";
coordinate="121.47967359286,31.242455049748";
costgraded=5;
foodgraded=5;
grade=5;
gradedcount=1;
id=18;
"name_e"="Shanghai City Bistro,Shanghai Marriott Hotel City Centre";
"name_s"="都会尚膳,上海雅居乐万豪酒店";
parkdetail="地下车库 其他 ";
payment="现金 刷卡 ";
placegraded=5;
restimg=("20131030/20131030053208705250y8RGHvp_thum549.jpg");
resttype="西餐厅";
seating=252;
servicegraded=5;
services="提前订位 接受预约 ";
telphone="021-23129724";
"trading_s"="其它";
zipcode="";
NSDictionary * arributes = [(NSArray *)[dicResult objectForKey:@"list"] objectAtIndex:0]; m_storeInfo = [StoreInfo parseEntityWithDictionary:arributes];