我AFJSONRequestOperation
用来请求远程 API:
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
//Remove the SVProgressHUD view
[SVProgressHUD dismiss];
//Check for the value returned from the server
NSData *jsonData = [JSON dataUsingEncoding:NSUTF8StringEncoding];//This line cause crash
NSArray *arr = [NSJSONSerialization JSONObjectWithData:jsonData
options:0
error:nil];
loginDic=[[NSDictionary alloc]init];
loginDic=[arr objectAtIndex:0];
NSLog(@"%@",loginDic);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error: %@", [error.userInfo objectForKey:@"NSLocalizedDescription"]);
}];
[operation start];
[SVProgressHUD showWithStatus:@"Loading"];
但是,应用程序崩溃了,我收到了这个错误:
[__NSCFDictionary dataUsingEncoding:]: unrecognized selector sent to instance
这是NSLog
返回的 JSON 对象的一个:
Result = (
{
operation = 5;
result = 1;
}
);
我是否遗漏了什么,因为我认为我没有正确解析 JSON 对象。请纠正我。