#import "URLService.h"
#import "HTTPService.h"
#import "News.h"
#define URL_TEST @"http://api.jisuapi.com/news/get"
@implementation URLService
-(void)getNewsWithChannel:(NSString *)channel num:(NSString *)num start:(NSString *)start appKey:(NSString *)key completion:(URLPass)completion{
NSDictionary *paramDic = @{
@"channel":channel,
@"num":num,
@"start":start,
@"appkey":@"de394933e1a3e2db"
};
[[[HTTPService alloc]init]POST:URL_TEST params:paramDic completion:^(id jsonData, BOOL success) {
// 将数据回传给controller
// completion(jsonData,YES);
NSString *status = jsonData[@"status"];
if ([status intValue]!= 0) {
completion(jsonData[@"msg"],NO);
return ;
}
// 如果result是0,得到result字典
NSDictionary *resultDic = jsonData[@"result"];
NSArray *listArr = resultDic[@"list"];
// 定义一个可变数组
NSMutableArray *newArr =[[ NSMutableArray alloc]init];
for (NSDictionary *dic in listArr) {
News *oneNew = [[News alloc]init];
[oneNew setValuesForKeysWithDictionary:dic];
[newArr addObject:oneNew];
}
// 将newArr回传给controller
completion(newArr,YES);
}];
}
@end