错误“autorelease”不可用:在自动引用计数模式下不可用

我试图使用Stig的JSON库进行HTTP请求和parsingJSON。 我得到这个错误'自动释放'是不可用的:当我使用这个代码不可用于自动引用计数模式

NSURLRequest *request2; request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://sandbox.CompanyName.com/api/%@/users/%@/user_badges?url=CompanyName.map2.com&amount=999999999999",[information stringForKey:@"apiKey"] , [information stringForKey:@"userID"]]]]; NSURLConnection *connection2; connection2 = [[NSURLConnection alloc] initWithRequest:request2 delegate:self startImmediately:YES]; NSURLResponse *resp2; NSData *cData2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&resp2 error:nil]; NSString *cDataString2 = [[NSString alloc] initWithData:cData2 encoding:NSUTF8StringEncoding]; NSLog(@"getUsersBadges called"); NSError *error4; SBJSON *json4 = [[SBJSON new] autorelease]; // NSArray *luckyNumbers = [json objectWithString:responseString error:&error]; NSDictionary *luckyNumbers4 = [json4 objectWithString:cDataString2 error:&error4]; [cDataString2 release]; 

UPDATE

对于任何感兴趣的人来说,这是正确的代码:NSURLRequest * request2; request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@“ http://sandbox.CompanyName.com/api/%@/users/%@/user_badges?url=CompanyName.map2.com&amount=999999999999 ”,[信息stringForKey:@“apiKey”],[信息stringForKey:@“userID”]]]];

 NSURLConnection *connection2; connection2 = [[NSURLConnection alloc] initWithRequest:request2 delegate:self startImmediately:YES]; NSURLResponse *resp2; NSData *cData2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&resp2 error:nil]; NSString *cDataString2 = [[NSString alloc] initWithData:cData2 encoding:NSUTF8StringEncoding]; NSLog(@"getUsersBadges called"); NSError *error4; SBJSON *json4 = [SBJSON new]; // NSArray *luckyNumbers = [json objectWithString:responseString error:&error]; NSDictionary *luckyNumbers4 = [json4 objectWithString:cDataString2 error:&error4]; 

更改

SBJSON *json4 = [[SBJSON new] autorelease];

SBJSON *json4 = [SBJSON new];

这将允许您完整保留自动引用计数。

你摆脱这个错误的方式是进入你的项目构build设置。 search自动引用计数。 一旦你发现它的值设置为“否”