我已经使用这种方法完成了我的应用程序,我正在实施的最后一个调用是一个简单的 JSON 响应,我需要对其进行解析,它给了我:
[__NSCFString objectAtIndexedSubscript:]: 无法识别的选择器发送到实例 0x17005caa0'
这个网站上有很多类似这样的问题,但我正在按照他们的指示做所有事情,但仍然没有运气。
它是 responseObject 中的嵌套 JSON。我得到了 responseObject,这意味着我发送的请求是正确的。
[[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];
}}
这是我作为 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;
}
所以cellForRowAtIndexPath
当我这样做时:
NSLog(@"%@", [NSString stringWithFormat:@"%@",allPracticeName[indexPath.row]]);
该应用程序因我在上面分享的消息而崩溃。