2016-11-19 100 views
-2

如何从此URL获取所有编号,并在uitableview“http://www.thomas-bayer.com/sqlrest/CUSTOMER/”中显示。XML解析获取编号

- (void)viewDidLoad 
{ 

    NSURL *URL = [[NSURL alloc] initWithString:@"http://www.thomas-bayer.com/sqlrest/CUSTOMER/"]; 

     NSString *xmlString = [[NSString alloc] initWithContentsOfURL:URL encoding:NSUTF8StringEncoding error:NULL]; 

     xmlDoc = [NSDictionary dictionaryWithXMLString:xmlString]; 


     NSLog(@"dictionary: %@", xmlDoc); 



    } 


    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return 1; 
    } 

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     return [xmlDoc count]; 
    } 


    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *cellID = @"Cell"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; 

     if (cell == nil) { 

      cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; 
     } 


     cell.textLabel.text = [[[xmlDoc objectForKey:@"CUSTOMER"]objectAtIndex:indexPath.row]objectForKey:@"__text"]; 


     return cell; 

    } 

我只得到0,1,2值显示在uitableview中,并忽略剩余的ID?

+0

你能告诉我们,你已经试过了吗? – FelixSFD

+0

我试图遵循一个非常类似于http://www.theappguruz.com/blog/xmlparsing-with-nsxmlparser-tutorial的xml教程,但最终没有显示任何内容。 – RKrish

回答

0

使用此库将XMLData转换为NSDictionary对象。 https://github.com/nicklockwood/XMLDictionary然后只需从NSDictionary对象中获取所需的数据并将其更新到TableView

+0

我只有0,1,2的值显示在uitableview中,并忽略剩余的ID? – RKrish

+0

请分享您的代码,以便我可以找到缺陷并​​告诉您。 –

+0

我也编辑你的问题现在检查它。 –