解析字典套数组套字典(有分业功能)

//解析字典套数组套字典
-(void)requestUrl{
    //NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    //[user valueForKey:@"用户"];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    if ([user valueForKey:@"用户"]==nil) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您还没有登录,请点击账户登录" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
//        [alert show];
//        [alert dismissWithClickedButtonIndex:3 animated:YES];
        
        UILabel *lx=[[UILabel alloc]init];
        lx.frame=CGRectMake(10, 100, [UIScreen mainScreen].bounds.size.width-20, 40);
        lx.text=@"啊哦!您还没有登录,什么东西都看不见";
        lx.textAlignment=NSTextAlignmentCenter;
        lx.textColor=[UIColor grayColor];
        [self.view addSubview:lx];
    }else{
    NSString *str=[NSString stringWithFormat:@"http://www.aliyueba.com:8080/ci/index.php/api/product/showAllCollectProd?userid=%@&page=1",[user valueForKey:@"用户"]];
    NSLog(@"用户%@",[user valueForKey:@"用户"]);
    
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    NSURL *url = [NSURL URLWithString:str];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    __weak typeof(self) weakSelf=self;
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //NSLog(@"++++++%@",responseObject);
        flagName=YES;
        if ([responseObject[@"msg"]isEqualToString:@"暂时还没有收藏产品!"]) {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"没有收藏产品" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
//            alert.delegate=self;
//            [alert show];
//            [alert dismissWithClickedButtonIndex:3 animated:YES];
            UILabel *l=[[UILabel alloc]init];
            l.frame=CGRectMake(10, 100, [UIScreen mainScreen].bounds.size.width-20, 40);
            l.text=@"没有收藏的产品";
            l.textAlignment=NSTextAlignmentCenter;
            l.textColor=[UIColor grayColor];
            [self.view addSubview:l];
        }else{
            _yelparr=responseObject[@"result"];

        }
        //        for (NSDictionary *d in responseObject[@"result"]) {
        //            [_yelparr addObject:d];
        //        }
//        [_yelparr removeAllObjects];
//        [_yelparr addObjectsFromArray:responseObject[@"result"]];
        //        _yelparr=responseObject[@"result"];
        [weakSelf.tableView reloadData];
        NSLog(@"yelparr++产品---%@",_yelparr);
        weakSelf.page=1;
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    }
    
}

-(void)requestUrl2{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    //[user valueForKey:@"密码"];
    self.page++;
    NSLog(@"page=%ld",self.page);
    NSString *str=[NSString stringWithFormat:@"http://www.aliyueba.com:8080/ci/index.php/api/product/showAllCollectProd?userid=%@&page=%ld",[user valueForKey:@"用户"],self.page];
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    NSURL *url = [NSURL URLWithString:str];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    __weak typeof(self) weakSelf=self;
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //NSLog(@"++++++%@",responseObject);
        flagName=YES;
        if ([responseObject[@"code"]isEqualToString:@"101"]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"没有更多了" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
            alert.delegate=self;
            [alert show];
            [alert dismissWithClickedButtonIndex:3 animated:YES];
        }else{
            //for (NSDictionary *d in responseObject[@"result"]) {
            //                [_yelparr addObject:d];
            //[_yelparr arrayByAddingObject:d];
            //[_yelparr addObjectsFromArray:responseObject[@"result"]];
            //                NSMutableArray *tempArr = [NSMutableArray array];
            //                for (NSDictionary *dic in responseObject[@"result"])
            //                {
            //                    [tempArr addObject:dic];
            //                }
            //                weakSelf.yelparr = tempArr;
            NSMutableArray *tempArr = [NSMutableArray arrayWithArray:_yelparr];
            for (NSDictionary *dic in responseObject[@"result"])
            {
                [tempArr addObject:dic];
            }
            _yelparr = [NSMutableArray arrayWithArray:tempArr];
            
            
            //}
            
            [weakSelf.tableView reloadData];
            //NSLog(@"yelparr++---%@",_yelparr);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}

//赋值

    cell.mingchenlabel.text=[_yelparr[indexPath.row]  objectForKey:@"name"];

你可能感兴趣的:(数组)