私は、私のAPI呼び出しの1つからの応答オブジェクトに苦労しています。私はそれを受け取りますが、オブジェクトに対してcountまたはvalueForKey操作を実行しようとすると、「インスタンスに送信されたセレクタが認識されません」というエラーが発生します。私は応答オブジェクトを正しくデコードしていないと感じています。入力は非常に高く評価されます。応答オブジェクトに対して操作を実行できませんか?
APIの呼び出し方法:
- (void)callRegisterAccount:(NSString *)email
password:(NSString *)password
confirmPassword:(NSString *)confirmPassword
completionBlock:(void (^)(NSMutableArray *resultsArray))completion{
NSLog(@"REGISTER ACCOUNT CALLED!");
NSString *appendUrl = [NSString stringWithFormat:@"Account/Register"];
NSURL *aUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@""%@", @"xxx", appendUrl]];
NSLog(@"URL: %@",aUrl);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
[request setHTTPMethod:@"POST"];
[request addValue:@"application/json, text/plain, */*" forHTTPHeaderField:@"Accept"];
[request addValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
//build an info object and convert to json
NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:
email,
@"Email",
password,
@"Password",
confirmPassword,
@"ConfirmPassword",
nil];
//convert object to data
NSError *error;
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:info
options:NSJSONWritingPrettyPrinted error:&error];
NSString *strData = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"%@",strData);
[request setHTTPBody:[strData dataUsingEncoding:NSUTF8StringEncoding]];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
// NSLog(@"REGISTER PUSH NOTIFICATIONS RESPONSE: %@", response);
// NSLog(@"REGISTER PUSH NOTIFICATIONS ERROR: %@", error);
// NSLog(@"REGISTER PUSH NOTIFICATIONS DATA: %@", data);
NSData *_data = data;
NSMutableString *_string = [NSMutableString stringWithString:@""];
for (int i = 0; i < _data.length; i++) {
unsigned char _byte;
[_data getBytes:&_byte range:NSMakeRange(i, 1)];
if (_byte >= 32 && _byte < 127) {
[_string appendFormat:@"%c", _byte];
} else {
[_string appendFormat:@"[%d]", _byte];
}
}
NSLog(@"REGISTER ACCOUNT RESPONSE: %@", _string);
if(_string) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
completion((NSMutableArray*)_string);
}
}];
}