@interface RootViewController ()<NSURLConnectionDataDelegate>
@property (nonatomic, strong) NSMutableArray *data;
@property (nonatomic, strong) NSMutableData *tempData;
@end
- (void)GetDelegateAction{
NSURL *url = [NSURL URLWithString:CQGETUEL];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[NSURLConnection connectionWithRequest:request delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
self.data = [NSMutableArray array];
self.tempData = [NSMutableData data];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[self.tempData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:self.tempData options:NSJSONReadingAllowFragments error:nil];
NSArray *arr = dict[@"news"];
for (NSDictionary *dic in arr) {
News *news = [[News alloc] init];
[news setValuesForKeysWithDictionary:dic];
[self.data addObject:news];
}
}