私は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オブジェクトを正しく解析していないと思うので、何か不足していますか? 私を修正してください。