setHeader

    NSURL *url = [NSURL URLWithString:homeURL];

    NSURL *url1 = [NSURL URLWithString:homeContentURL];

    

    

    

    

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];

    NSURLRequest *request1 = [NSURLRequest requestWithURL:url1];

    

    

    

    [request setValue:@"m_hd_type is iphone6" forHTTPHeaderField:@"lang"];

    

    

    

    

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation allocinitWithRequest:request];

    AFHTTPRequestOperation *operation1 = [[AFHTTPRequestOperation allocinitWithRequest:request1];

    

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSString *html = operation.responseString;

        NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];

        NSDictionary * dict=[NSJSONSerialization  JSONObjectWithData:data options:0 error:nil];

        _pagemodel.shufflingArray = [[NSMutableArray alloc]initWithCapacity:[[dict objectForKey:@"results"count]];

        for (NSDictionary *dic in [dict objectForKey:@"results"]) {

            [_pagemodel.shufflingArray addObject:[dic objectForKey:@"imgUrl"]];

        }

        [_collectionView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];

        

    }failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"发生错误!%@",error);

        

    }];

    

    [operation1 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation1, id responseObject) {

        NSString *html = operation1.responseString;

        NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];

        NSMutableDictionary *dict=[NSJSONSerialization  JSONObjectWithData:data options:0 error:nil];

        NSLog(@"获取到的数据为:%@",dict);

        NSLog(@"%@",[[[dict objectForKey:@"results"]objectAtIndex:0]objectForKey:@"areaName"]);

        

        _pagemodel.homeArray = [[NSMutableArray alloc]initWithCapacity:[[dict objectForKey:@"results"count]];

        for (NSDictionary *dic in [dict objectForKey:@"results"]) {

            HomeModel *home = [[HomeModel alloc]init];

            [home setValuesForKeysWithDictionary:dic];

            [_pagemodel.homeArray addObject:home];

            [home release];

        }

        NSLog(@"%@",_pagemodel.homeArray);

        

        [_collectionView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];

     }failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"发生错误!%@",error);

    }];

    NSOperationQueue *queue = [[NSOperationQueue allocinit];

    [queue addOperation:operation];

    [queue addOperation:operation1];

你可能感兴趣的:(ios,iPhone)