好吧,我正在解析来自 json 的数据,并将它们动态添加到数组中。如果我添加其中的 12 个数据,就可以了。但是当我要添加第 13 个时,我得到了这个错误(不管第 13 个是什么):
EXC_BAD_ACCESS
这是我的代码:
HomeView.h
#import <UIKit/UIKit.h>
@interface HomeView : UIViewController{
NSMutableData *responseData;
}
@property (nonatomic, strong) NSMutableData *responseData;
@end
和我的实现文件:
@implementation HomeView
@synthesize responseData;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"connectionDidFinishLoading");
NSLog(@"Succeeded! Received %d bytes of data",[self.responseData length]);
// convert to JSON
NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];
NSString *parsed_track=[res objectForKey:@"data1"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data2"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data3"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data4"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data5"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data6"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data7"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data8"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data9"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data10"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data11"];
[tracks_condition addObject:parsed_track];
parsed_track=[res objectForKey:@"data12"];
[tracks_condition addObject:parsed_track];
// parsed_track=[res objectForKey:@"data13"]; //HERE COMES THE ERROR
// [tracks_condition addObject:parsed_track];
}
我想这是内存管理的问题,但我不知道是什么。