请求服务器

屏幕快照 2016-11-02 上午11.07.38.png

](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"];
屏幕快照 2016-11-03 上午9.41.02.png

上传数据:

 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];

屏幕快照 2016-11-07 下午4.44.02.png

'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]}

屏幕快照 2016-11-09 下午6.13.21.png
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"}; }

屏幕快照 2016-11-10 上午10.31.53.png
屏幕快照 2016-12-01 下午6.10.07.png

对于返回的数据解析:

   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]
    };
    }```
屏幕快照 2016-12-05 下午7.10.09.png
屏幕快照 2016-12-08 下午2.54.47.png

在向服务器发送数据时候,把字典发送给服务器

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":"饕餮"}]'

屏幕快照 2016-12-14 上午11.48.32.png
屏幕快照 2016-12-14 下午2.03.05.png
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"]];
屏幕快照 2016-12-14 下午5.16.47.png

解析:

 if ([response.responseObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *dict = response.responseObject;
self.payTypeImageList = [NSArray yy_modelArrayWithClass:[TDFPayTypeImageModel class] json:dict[@"data"]];
屏幕快照 2016-12-14 下午5.27.49.png

解析:

 if ([response isSuccess]) {
           if ([response.responseObject isKindOfClass:[NSDictionary class]]) {
           NSDictionary *dict = response.responseObject;
           NSArray<TDFBusinessSpellModel *> *dataList = [NSArray yy_modelArrayWithClass:[TDFBusinessSpellModel class] json:dict[@"data"]];
}
}
屏幕快照 2016-12-15 下午3.49.07.png

解析:

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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,198评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,663评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,985评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,673评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,994评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,399评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,717评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,407评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,112评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,371评论 2 241
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,891评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,255评论 2 250
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,881评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,010评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,764评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,412评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,299评论 2 260

推荐阅读更多精彩内容