【发布时间】:2016-10-18 11:13:56
【问题描述】:
我正在尝试从 json 网络服务中获取结果。对于字符串值,它工作正常。当我尝试获取整数值时,它会抛出带有 sigbart 错误的 nsexeption。
我的 json 结果是这样的。
[{"CaseId":81,"ApplicantName":"test","ApplicantContactNo":"teas","PropertyAddress":"ewae","BankName":"Bank of India","ReportDispatcher":null,"PropertyType":"test","AssignedAt":"2016-10-07T13:01:20","Status":"Open","PropertyId":62,"EmployeeName":null,"StatusId":1}
当我尝试捕获 CaseId 和 AssignedAt 时,它会抛出错误。
这是我的代码。
NSString * caseid = @"CaseId";
NSString * assigned = @"AssignedAt";
for (NSDictionary *dataDict in jsonObjects) {
NSString *caseid1 = [dataDict objectForKey:@"CaseId"];
NSString *assigned1 = [dataDict objectForKey:@"AssignedAt"];
dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
caseid1,caseid,assigned1,assigned, nil];
[myObject addObject:dictionary];
}
cell.caseid.text=[tmpDict objectForKey:@"CaseId"];
cell.days.text=[tmpDict objectForKey:@"AssignedAt"];
任何帮助将不胜感激。
【问题讨论】:
-
你应该给出错误。但可能猜测是有一个“[NSNumber length] unrecognized selector sent to instance”。
NSJSONSerialization将NSData转换为NSArray、NSDictionary、NSString和NSNumber。您可以使用[[tmpDict objectForKey:@"CaseId"] class]进行检查。所以cell.caseid.text=[[tmpDict objectForKey:@"CaseId"] stringValue];应该可以工作。
标签: ios objective-c json web-services