本文介绍了错误'autorelease'不可用:在自动参考计数模式下不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试发出HTTP请求并使用Stig的JSON库解析JSON。我收到此错误'autorelease'不可用:当我使用此代码时,无法在自动引用计数模式下使用

I trying to make a HTTP request and parse JSON using Stig's JSON Library. I'm getting this error 'autorelease' is unavailable: not available in automatic reference counting mode when I use this code

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;
请求2 = [的NSURLRequest requestWithURL:[NSURL URLWithString:[的NSString stringWithFormat:@ ,[information stringForKey:@apiKey],[information stringForKey:@userID]]]];

For anyone interested, this is the correct code: 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];
// NSArray *luckyNumbers = [json objectWithString:responseString error:&error];
NSDictionary *luckyNumbers4 = [json4 objectWithString:cDataString2 error:&error4];


推荐答案

更改

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

to

SBJSON * json4 = [SBJSON new];

这将允许您保持自动引用计数不变。

This will allow you to leave automatic reference counting intact.

这篇关于错误'autorelease'不可用:在自动参考计数模式下不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 15:54