0

我将从 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 丢失。我哪里错了?

4

0 回答 0