-[__NSArrayI 对象索引:]: 索引 1 超出边界 [0 .. 0]'


@implementation BasicProfileView
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.scrollView addSubview:_basicProfileView];
    [_scrollView setContentSize:self.basicProfileView.frame.size];
    gender=@"0";
    seekingGender=@"0";
    _basicProfileView.backgroundColor=[UIColor clearColor];
   }
- (IBAction)btnContinue:(id)sender {
[self callSignupProfileService];
    }
-(void)callSignupProfileService
{
 NSString * post = [[NSString alloc]initWithFormat:@"userId=%@&cell_phone=%@&work_phone=%@&gender=%@&seekgender=%@&address=%@&country=%@&state=%@&city=%@&motherTongue=%@&zipcode=%@",UserId,_txtCellPhone.text,_txtWorkPhone.text,gender,seekingGender,_txtAdress.text,_WSConstCountryID,_WSConstStateID,_WSConstCityID,_WSConstLanguageID,_txtZipcode.text];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"URL"]];
    RBConnect = [[RBConnection alloc]init];
    RBConnect.delegate = self;
    [RBConnect postRequestForUrl:url postBody:post];
}
- (void)jsonData:(NSDictionary *)jsonDict
{
    [SVProgressHUD dismiss];
    NSMutableArray *jsonArr;
    NSMutableDictionary *userDict,*dict;
    jsonArr=[jsonDict objectForKey:@"DataTable"];
dict=[jsonArr objectAtIndex:0];
    userDict=[dict objectForKey:@"ABSUserProfile"];

if (userDict.count>2) {

    self.navigationController.navigationBarHidden=YES;
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"  bundle: nil];
    ECSlidingViewController *newView = [mainStoryboard instantiateViewControllerWithIdentifier:@"slidingmenu"];
    [self.navigationController pushViewController:newView animated:YES];

}
else
{
    NSString *error=@"Somthing Went Wrong";
    [SVProgressHUD showErrorWithStatus:error];
}
  }

遇到了以下问题。请帮我解决这个问题。蒂亚

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x246af91b 0x23e4ae17 0x245c1987 0x6b4d3 0x28c430e5 0x28c42e87 0xb0ecf 0xb099d 0xaf5d9 0xaf3ad 0xaf2d1 0x7fa23 0x28c62755 0x28de3b91 0x28c62755 0x28c626e1 0x28c4a6d3 0x28c4a7ff 0x28c62005 0x28c61c7f 0x28c5a68f 0x28c2b125 0x28c296d3 0x24671dff 0x246719ed 0x2466fd5b 0x245bf229 0x245bf015 0x25bafac9 0x28c93189 0xca8a9 0x24267873)
libc++abi.dylib: terminating with uncaught exception of type NSException

检查这个,

@implementation BasicProfileView
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    jsonArr = [NSMutableArray new];
    [self.scrollView addSubview:_basicProfileView];
    [_scrollView setContentSize:self.basicProfileView.frame.size];
    gender=@"0";
    seekingGender=@"0";
    _basicProfileView.backgroundColor=[UIColor clearColor];
   }
- (IBAction)btnContinue:(id)sender {
[self callSignupProfileService];
    }
-(void)callSignupProfileService
{
 NSString * post = [[NSString alloc]initWithFormat:@"userId=%@&cell_phone=%@&work_phone=%@&gender=%@&seekgender=%@&address=%@&country=%@&state=%@&city=%@&motherTongue=%@&zipcode=%@",UserId,_txtCellPhone.text,_txtWorkPhone.text,gender,seekingGender,_txtAdress.text,_WSConstCountryID,_WSConstStateID,_WSConstCityID,_WSConstLanguageID,_txtZipcode.text];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"URL"]];
    RBConnect = [[RBConnection alloc]init];
    RBConnect.delegate = self;
    [RBConnect postRequestForUrl:url postBody:post];
}
- (void)jsonData:(NSDictionary *)jsonDict
{
    [SVProgressHUD dismiss];
    NSMutableArray *jsonArr;
    NSMutableDictionary *userDict,*dict;
    jsonArr=[jsonDict objectForKey:@"DataTable"];
   if (jsonArr != nil && [jsonArr count] > 0) {
   dict=[jsonArr objectAtIndex:0];
   userDict=[dict objectForKey:@"ABSUserProfile"];
    if (userDict.count>2) {
        self.navigationController.navigationBarHidden=YES;
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"  bundle: nil];
        ECSlidingViewController *newView = [mainStoryboard instantiateViewControllerWithIdentifier:@"slidingmenu"];
        [self.navigationController pushViewController:newView animated:YES];
   }
}
else
{
    NSString *error=@"Somthing Went Wrong";
    [SVProgressHUD showErrorWithStatus:error];
}
  }
NSMutableArray *jsonArr;

您需要添加

jsonArr = [NSMutableArray alloc] init];

Alway 初始化

在您的- (void)jsonData:(NSDictionary *)jsonDict中,更改:

jsonArr=[jsonDict objectForKey:@"DataTable"];

jsonArr = [[NSMutableArray alloc] initWithArray:[jsonDict objectForKey:@"DataTable"]];

现在更改:

dict=[jsonArr objectAtIndex:0];

自:

if([jsonArr count]>0){
    dict=[jsonArr objectAtIndex:0];
    //Do whatever you want, your jsonArr is valid as it has objects
}
else{
//Perform necessary action here as your jsonArr is empty
}

最新更新