EXC_BAD_ACCESS after converting HTTP response to string
I have the following code, from which I am getting an EXC_BAD_ACCESS error:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(responseString);
}
The weird thing is, the bad access error is actually coming from the NSLog() line, when it tries to access responseString. I've even tried adding a retain or autorelease to the first line, but I still get the error.
Any thoughts on what might be happening? To my knowledge, there shouldn't be any issue, because I'm calling it immediately after it's defined, so responseString should not have been released yet, correct?
EDIT: I shou开发者_开发百科ld mention, receivedData is an NSMutableData object.
Try
NSLog(@"%@", responseString);
Your responseString might have some 'reserved sequences', like %@ or %d.
The former will cause NSLog to access 'object' in arbitrary location in memory, since it doesn't know (or doesn't care) how many parameters you actually provided.
Try NSLog (@"%@", responseString);
加载中,请稍侯......
精彩评论