](http://upload-images.jianshu.io/upload_images/1436896-b1868dab002de57a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
在发送参数时,param用[self yy_modelToJSONString];
在接收参数以后,把参数放到一个Vo模型中。可以在模型实现中:
- (void)encodeWithCoder:(NSCoder *)aCoder {
[self yy_modelEncodeWithCoder:aCoder];
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super init]; return [self yy_modelInitWithCoder:aDecoder];
}
- (id)copyWithZone:(NSZone *)zone {
return [self yy_modelCopy];
}
- (NSUInteger)hash {
return [self yy_modelHash];
}
- (BOOL)isEqual:(id)object {
return [self yy_modelIsEqual:object];
}
- (NSString *)description {
return [self yy_modelDescription];
}
在请求的success 的block中:
ResultVo *resultVo = [ResultVo yy_modelWithJSON:data[@"data"]];
对于data中userShopVo的字典要取出来的话:
NSDictionary *shopDic;
shopDic = [resultVo.userShopVo objectForKey:@"shop"];
上传数据:
NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
param[@"entity_id"] = self.entityId;
param[@"role_id"] = self.role.id;
param[@"action_id_list_json"] = [JsonHelper arrTransJson:items];
param[@"type"] = self.event;
JsonHelp里面的
+(NSString *)arrTransJson:(NSMutableArray*)arrs{
if (arrs==nil) {
arrs=[NSMutableArray array];
}
NSString *returnString = [arrs JSONString];
return returnString;
}```
![屏幕快照 2016-11-03 上午9.49.28.png](http://upload-images.jianshu.io/upload_images/1436896-78def56bb7d4edb2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![屏幕快照 2016-11-03 上午9.49.47.png](http://upload-images.jianshu.io/upload_images/1436896-2dc8d05db6ac6e75.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
上传参数:
NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
[param setObject:self.entityId forKey:@"entity_id"];
[param setObject:roleId forKey:@"role_id"];
```
解析服务器返回的data里面有4个List,每个List里面可能还有dictionary.
NSMutableDictionary *dic = data[@"data"];
NSMutableArray *branchArr = [[NSArray yy_modelArrayWithClass:[Action class] json:dic[@"branchActionList"]] mutableCopy];
NSMutableArray *chainArr = [[NSArray yy_modelArrayWithClass:[Action class] json:dic[@"chainActionList"]] mutableCopy];
NSMutableArray *managerArr = [[NSArray yy_modelArrayWithClass:[Action class] json:dic[@"shopRestActionList"]] mutableCopy];
'isHideIds'=$'["432b4d052c8a9fc690084a60618cdfec"]'
‘isShowIds'=$'["23ee46a55526dce3327e687b88407dad","fcc132f3c668afc2e8085d7c6106ae50","41e0af2ec90debf49a2ba82b0b884616","b109204dab28f1351c2c8f24eb1e9255","75099ef02b1900d0c6aa1970b39f5f11","5bef4aa2edcf718eb21fec109ad0becf","021901de41a3060c7d81a06cf27ff353","11b2a8284707ff100211060eedb7afd2","cf2741d360a991fa96c680765106c5db","ecd8cf9352306a150169f5699ccfb0ae","6bb481e01ea2f06ed0081c65a45b2856","51f11e093eabeb9bbf874f7fc416879a","684d5eaad060f8836bbe09e5158bcaba","b464e6e5a4bbf3dbc33d90e646c6f793","3dbef7f71c12ea25282bfee9d119479d","e691cc2f9a8e4ec80619b737cceceb7f","ceb8af634c32b0e01887d5b63cf4bcd3","9370bde527cd6695870194d2eae68eb5","86bdd57bac850f77ac8956359d35bac2","4c681fdbab640038aa3f512dee425af8","572f2f6dcf0c7e52e910168a600cdb59","884c7832cb2a0e61b4645410e8fb481f","d08113e16e42e025ccf2cea88ca73633","ac0640977606f45e537f75624e4beabb"]'
解析:
@{@"isShowIds":[isShowIds yy_modelToJSONString],@"isHideIds":[isHideIds yy_modelToJSONString]}
NSDictionary *dataDictionary = data[@"data"];
NSArray *dataArray = dataDictionary[@"operationModes"];
for (NSDictionary *dic in dataArray) {
TDFOperationModeModel *model = [TDFOperationModeModel yy_modelWithDictionary:dic];
[self.operationModeArray addObject:model];
}
if (dataDictionary[@"defaultOperationMode"]) {
TDFOperationModeModel *model = [TDFOperationModeModel yy_modelWithDictionary:dataDictionary[@"defaultOperationMode"]];
self.selectOperationModeModel = model;
}else
{
self.selectOperationModeModel = [self.operationModeArray firstObject];
}
TDFOperationModeModel:
包含了operationMode的字段,
+ (NSDictionary *)modelCustomPropertyMapper { return @{@"operationModeID" : @"id"}; }
对于返回的数据解析:
self.levelList = [NSArray yy_modelArrayWithClass:[TDFCustomerLevelModel class] json:data[@"data"]];```
![屏幕快照 2016-12-05 下午7.02.07.png](http://upload-images.jianshu.io/upload_images/1436896-744d71999908c115.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![屏幕快照 2016-12-05 下午7.04.49.png](http://upload-images.jianshu.io/upload_images/1436896-fe6e4d052d3461ed.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
对于返回的数据有两个Array(copy),一个BOOL值,对于NSArray用yy_model时候要加
- (NSDictionary *)modelContainerPropertyGenericClass {
// value should be Class or Class name.
return @{@"customerGrowthVos" : [TDFCustomerGrowthModel class],
@"customerPrivilegeVos" : [TDFCustomerPrivilegeModel class]
};
}```
在向服务器发送数据时候,把字典发送给服务器
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:2];
dic[@"level_settings_json"] = [self.levelList yy_modelToJSONString];
此时传给服务器的就是:
level_settings_json'=$'[
{"cellType":0,"level":0,"lastVer":"0","hasAddFooter":false,"growthValue":0,"name":"平民"},
{"cellType":0,"level":1,"lastVer":"0","hasAddFooter":false,"growthValue":825,"name":"吃货"},
{"cellType":0,"level":2,"lastVer":"0","hasAddFooter":false,"growthValue":2445,"name":"吃客"},
{"cellType":0,"level":3,"lastVer":"0","hasAddFooter":false,"growthValue":4890,"name":"吃霸"},
{"cellType":0,"level":4,"lastVer":"0","hasAddFooter":false,"growthValue":8250,"name":"食圣"},
{"cellType":0,"level":5,"lastVer":"0","hasAddFooter":false,"growthValue":13040,"name":"食神"},
{"cellType":0,"level":6,"lastVer":"0","hasAddFooter":false,"growthValue":24450,"name":"食仙"},
{"cellType":0,"level":7,"lastVer":"0","hasAddFooter":false,"growthValue":48900,"name":"饕餮"}]'
NSDictionary *dict = response.responseObject;
NSDictionary *dataDict = dict[@"data"];
self.dayModelList = [NSArray yy_modelArrayWithClass:[TDFBusinessInfoModel class] json:dataDict[@"days"]];
TDFBusinessInfoModel *monthModel = [TDFBusinessInfoModel yy_modelWithJSON:dataDict[@"month"]];
解析:
if ([response.responseObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *dict = response.responseObject;
self.payTypeImageList = [NSArray yy_modelArrayWithClass:[TDFPayTypeImageModel class] json:dict[@"data"]];
解析:
if ([response isSuccess]) {
if ([response.responseObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *dict = response.responseObject;
NSArray<TDFBusinessSpellModel *> *dataList = [NSArray yy_modelArrayWithClass:[TDFBusinessSpellModel class] json:dict[@"data"]];
}
}
解析:
NSDictionary *dict = response.responseObject;
NSArray<TDFPayInfoModel *> *payInfoList = [NSArray yy_modelArrayWithClass:[TDFPayInfoModel class] json:dict[@"data"]];
[self addImageUrlToList:payInfoList];
NSArray<TDFPayInfoModel *> *fullPayInfoList = [self generateFullPayInfoListWithFetchedPayInfoList:payInfoList];
[self.headerView configureViewWithPayInfoList:fullPayInfoList];