I currently trying to connect to a Webserver, and consuming a table from it. I have put the table into a NSMutable array (it's global), named it DataSet (I got this part working). However When I try to preform any type of operation on it (Example: count), it will give me a EXC_BAD_ACCESS. BTW I'm using xcode 4.2 with ARC, so it's not a memory management issue. Any suggestions?
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString: @"`url.com`"];
NSData *jsonData =[NSData dataWithContentsOfURL:url];
if(jsonData)
{
xmlParser = [[NSXMLParser alloc] initWithData: jsonData];
[xmlParser setDelegate: self];
[xmlParser parse];
}
NSLog(@"This is Number of elements: %@",[DataSet count]); ///<----EXC_BAD_ACCESS
..... //// default stuff//.....
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"string"])
{
/// puts the data into Array luckyNumbers
NSError *error;
SBJsonParser *json = [[SBJsonParser new] init];
DataSet = [[NSMutableArray alloc] init];
DataSet = [json objectWithString:soapResults error:&error];
/// NSLog(@"%@",DataSet); /// this works
}
}
I'm not sure if I'm suppose to but, I read that I should use Diagnostics, so I turned on NSZombie objects, Malloc guard, and Malloc Stack. They said I should type this into the gdb console info malloc-history (memorylocation)
However I don't know where to get the memory location of the problem. I would appreciate any help.
I couldn't get this to work, so I tried using and NSDictionary instead of NSArray and surprisingly it work! Here is my updated code for anyone who was wondering what I did.
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString: @"url.com"];
NSData *jsonData =[NSData dataWithContentsOfURL:url];
DataSet = [[NSDictionary alloc] init];
if(jsonData) {
xmlParser = [[NSXMLParser alloc] initWithData: jsonData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
}
NSLog(@"%@",DataSet.allKeys);
///// default stuff /// } }
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"string"])
{
//NSLog(@"%@",DataSet);
DataSet = [soapResults JSONValue];
NSLog(@"%@",DataSet);
}
}