18

HTTP リクエストを作成し、Stig の JSON ライブラリを使用して JSON を解析しようとしています。このエラー 'autorelease' is available: 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]; 

アップデート

興味のある方は、これが正しいコードです: 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];
4

2 に答える 2

23

このエラーを取り除く方法は、プロジェクトのビルド設定に入ることです。自動参照カウントを検索します。見つかったら、値を「NO」に設定します

于 2011-08-03T20:12:58.730 に答える
21

変化する

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

SBJSON *json4 = [SBJSON new];

これにより、自動参照カウントをそのままにしておくことができます。

于 2011-10-19T14:21:37.080 に答える