美文网首页
请求服务器

请求服务器

作者: 向着阳光奔跑的小孩 | 来源:发表于2016-12-01 18:14 被阅读40次
屏幕快照 2016-11-02 上午11.07.38.png
](https://img.haomeiwen.com/i1436896/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](https://img.haomeiwen.com/i1436896/78def56bb7d4edb2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![屏幕快照 2016-11-03 上午9.49.47.png](https://img.haomeiwen.com/i1436896/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](https://img.haomeiwen.com/i1436896/744d71999908c115.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![屏幕快照 2016-12-05 下午7.04.49.png](https://img.haomeiwen.com/i1436896/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];

相关文章

  • Servlet与SpringMVC运行流程

    整体流程(针对Servlet的请求): -->客户发出请求 -->Web服务器收到请求 -->Web服务器转交请求...

  • 1-(3)nginx负载均衡

    1、概述    增加服务器的数量,然后将请求分发到各个服务器上,将原先请求集中到单个服务器上的请求改为将请求分发到...

  • 从输入URL到页面展现

    分为如下过程: 域名解析 向web服务器发起请求 服务器处理请求 服务器响应请求 浏览器显示页面 过程详述 输入域...

  • response

    服务器处理请求的流程: 服务器每次收到请求时,都会为这个请求开辟一个新的线程服务器会把客户端的请求数据封装到req...

  • iOS随笔

    基础...objc 客户端:clien 服务器:server 请求:客户端向服务器发送请求 响应:返回数据,对请求...

  • 总结 5(http协议与chorme抓包,cookie,ajax

    get 请求:从服务器获取数据,并不会对服务器资源产生影响的,使用get请求(一般情况) post请求:向服务器发...

  • 请说出至少 8 个 HTTP 状态码,并描述各状态码的意义

    200 请求成功,服务器已成功处理了请求 201 已创建 ,请求成功且服务器创建了新的资源 301 永久移动,请求...

  • http请求头 响应头

    通常HTTP消息包括客户机向服务器的请求消息和服务器向客户机的响应消息。客户端向服务器发送一个请求,请求头包含请求...

  • HTTP

    请求与响应 1.浏览器向服务器发送请求2.服务器接受请求3.服务器返回内容HTTP作用就是规定浏览器和服务器如何进...

  • JavaWeb——服务器软件

    web服务器软件 服务器:安装了服务器软件的计算机 服务器软件:接收用户的请求,处理请求,做出响应 web服务器软...

网友评论

      本文标题:请求服务器

      本文链接:https://www.haomeiwen.com/subject/mcyvuttx.html