我正在通过NSXMLParser进行XML解析。 但是当涉及到NSXMLParser的didendElement时,它会在某些时候崩溃并且有时会给出结果。我无法理解我哪里出错了?
arr3=[[NSMutableArray alloc] init];
drr3=[[NSMutableDictionary alloc]init];
NSURL *urlString2= [NSString stringWithFormat:@"http://www.XXX.YYY/services/SService.svc/Get"];
currentURL=@"1";
/// calling the service url and getting the repsnse in array (arr3)
if([arr3 count]==0)
{
currentURL=@"2";
//calling another service url and storing in arr3.
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if(currentURL==@"1")
{
if([elementName isEqualToString:@"PWList"])
{
arr3=[[NSMutableArray alloc] init];
drr3=[[NSMutableDictionary alloc] init];
}
if([elementName isEqualToString:@"Name"])
{
drr3=[[NSMutableDictionary alloc] init];
}
srr3=[[NSMutableString alloc] init];
}
if(currentURL==@"2")
{
if([elementName isEqualToString:@"WeeksList"])
{
arr3=[[NSMutableArray alloc] init];
}
if([elementName isEqualToString:@"Person"])
{
drr3=[[NSMutableDictionary alloc]init];
}
srr3=[[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if(curentURL==@"1")
{
//some code
if([elementName isEqualToString:@"PWList"])
{
[drr3 release],drr3=nil;
}
}
if(curentURL==@"2")
{
if([elementName isEqualToString:@"Code"])
{
[drr3 setObject:srr3 forKey:@"Code"]; //crashes at this line
[srr3 release],srr3=nil;
return;
}
}
}
[drr3 setObject:srr3 forKey:@"Code"];
给出了错误“__NSDictionaryM setObject:forKey:]: message sent to deallocated instance".
有时候我会得到结果。
我该怎么做才能摆脱这个错误?