I've finished my app using this method and the last call I'm implementing is a simple JSON response which I need to parse and it is giving me:
[__NSCFString objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x17005caa0'
There are a lot of smililar questions like this on this website but I'm doing everything as they directed but still no luck.
It's a nested JSON in responseObject. I'm getting the responseObject which means the request I'm sending is correct.
[[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error){
if (!error) {
if (response) {
allResponse = [[NSMutableArray alloc] init];
allPractice = [[NSMutableArray alloc] init];
allProvider = [[NSMutableArray alloc] init];
allFirstName = [[NSMutableArray alloc] init];
allMiddleName = [[NSMutableArray alloc] init];
allLastName = [[NSMutableArray alloc] init];
allPracticeName = [[NSMutableArray alloc] init];
allResponse = responseObject;
allPractice = [allResponse valueForKey:@"Practice"];
allProvider = [allResponse valueForKey:@"Provider"];
allFirstName = [allProvider valueForKey:@"FirstName"];
allMiddleName = [allProvider valueForKey:@"MiddleName"];
allLastName = [allProvider valueForKey:@"LastName"];
allPracticeName = [allPractice valueForKey:@"PracticeAlias"];
[self.tableView reloadData];
[SVProgressHUD dismiss];
}}
Here is the structure I'm getting as ResponseObjects.
{
AccountType = 2;
CreatedBy = smith;
CreatedDate = "2016-01-25T02:07:42.45";
DisplayName = ", ";
Email = "<null>";
ErrorMessage = "<null>";
FirstName = "<null>";
ID = 1;
IsActive = 1;
Password = test;
Phone = "<null>";
Practice = {
PracticeAlias = “SAMPLE MEDICAL GROUP";
};
PracticeAlias = "<null>";
PracticeCode = "<null>";
PracticeID = 1;
Provider = {
AccountType = 0;
CreatedBy = smith;
LastName = John;
MiddleName = "";
FirstName = Smith;
};
Staff = "<null>";
lstPractice = "<null>";
lstProvider = "<null>";
pageSize = 0;
}
So in cellForRowAtIndexPath
when I do this:
NSLog(@"%@", [NSString stringWithFormat:@"%@",allPracticeName[indexPath.row]]);
The app crash with the message I shared above.
allPracticeName
is of type NSString
(with value "< null >"). You are calling a subscript operator []
on this string:
allPracticeName[indexPath.row]
but NSString
has no subscript implementation.
Remove the subscript:
NSLog(allPracticeName);