添加到NSMutableArray不添加iPhone(Xcode)中的最后一个值?

时间:2012-10-03 12:37:49

标签: ios xml-parsing nsmutablearray nsxmlparser

我将从XML Parser获取的数据添加到NSMUtableArray,我看到除了最后一个值之外还添加了所有值

我的XML响应是这样的:

<List1>
 <CompanyProvider>
    <TimeStart>11:00</TimeStart>
  </CompanyProvider>
  <CompanyProvider>
    <TimeStart>11:15</TimeStart>
 </CompanyProvider>
 <CompanyProvider>
    <TimeStart>11:30</TimeStart>
 </CompanyProvider>
 <CompanyProvider>
    <TimeStart>11:45</TimeStart>
 </CompanyProvider>
<List1>
<CompanyTimeList>
   <CompanyProvider>
     <TimeStart>11:00</TimeStart>
   </CompanyProvider>
   <CompanyProvider>
     <TimeStart>11:15</TimeStart>
   </CompanyProvider>
   <CompanyProvider>
     <TimeStart>11:30</TimeStart>
   </CompanyProvider>
   <CompanyProvider>
     <TimeStart>11:45</TimeStart>
   </CompanyProvider>
</CompanyTimeList>

我必须从CompanyTimeList中消耗TimeStart的值 我正在使用的代码是:

-(void)ButtonClicked
{
    arr1 = [[NSMutableArray alloc] init];
    drr1 = [[NSMutableDictionary alloc] init];

    NSString *urlString = [NSString stringWithFormat:@"http://192.168.0.101:8732/Design_Time_Addresses/IServices/AppointmentService/json/GetAppointments/?cid=999a18dd-50a6-4da0-b692-ef173834435b&pid=aee49598-6199-4f57-90e2-654da651c944&wk=Tuesday&dt=10/16/2012"];    
    NSURL *jsonUrl =[NSURL URLWithString:urlString];
    NSString *jsonStr = [[NSString alloc] initWithContentsOfURL:jsonUrl];  
    NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:jsonUrl];      

    [parser setDelegate:self];
    [parser setShouldProcessNamespaces:NO];
    [parser setShouldReportNamespacePrefixes:NO];
    [parser setShouldResolveExternalEntities:NO];
    [parser parse];
    [parser release];

    NSLog(@"%@",arr1);      
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    element = elementName;

    if([elementName isEqualToString:@"CompanyTimeList"])
    {
        arr1 = [[NSMutableArray alloc] init];
        drr1 = [[NSMutableDictionary alloc] init];   
    }

    if([elementName isEqualToString:@"CompanyProvider"])
    { 
        drr1 = [[NSMutableDictionary alloc] init];        
    }

    srr1 = [[NSMutableString alloc] init];
} 

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    [srr1 appendString:string];
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if([elementName isEqualToString:@"TimeStart"])
    {    
        [drr1 setObject:srr1 forKey:@"TimeStart"];
        [srr1 release],srr1=nil;
        return;
    }  

    if([elementName isEqualToString:@"CompanyProvider"]) 
    { 
        [arr1 addObject:drr1]; 
    }    

    if([elementName isEqualToString:@"CompanyTimeList"])
    {      
        [drr1 release];  
    }

    [srr1 release], srr1 = nil;
}

但我能看到的回应是:

(
    {
        TimeStart="11:00"
    },
    {
        TimeStart="11:15"
    },
    {
        TimeStart="11:30"
    }
    {
        TimeStart=""
    }
)

我看不到最后一个值,即11:45.Y缺失。我哪里错了?

0 个答案:

没有答案