ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 低调看直播体育app软件下载 >> IOS开发 >> iOS xml文件的解析方式 XMLDictionary,GDataXMLNode,NSXMLParser

iOS xml文件的解析方式 XMLDictionary,GDataXMLNode,NSXMLParser(1/3)

来源:网络整理     时间:2016-03-26     关键词:

本篇文章主要介绍了"iOS xml文件的解析方式 XMLDictionary,GDataXMLNode,NSXMLParser",主要涉及到方面的内容,对于IOS开发感兴趣的同学可以参考一下: iOS9之后,默认网络请求是https,所有我们要设置一下网络安全,具体设置如下1.第三方类库 XMLDictionary下载地址:https://github...

iOS9之后,默认网络请求是https,所有我们要设置一下网络安全,具体设置如下

iOS xml文件的解析方式 XMLDictionary,GDataXMLNode,NSXMLParser

1.第三方类库 XMLDictionary

下载地址:

https://github.com/nicklockwood/XMLDictionary

 

所用到的xml文件

http://www.meituan.com/api/v1/divisions?mtt=1.help%2Fapi.0.0.im7eandj

效果如下:

iOS xml文件的解析方式 XMLDictionary,GDataXMLNode,NSXMLParser

代码实现:

根视图:

rootTableViewController.m文件

#import"rootTableViewController.h"#import"XMLDictionary.h"#import"secondViewController.h"@interface rootTableViewController ()
@property(nonatomic,strong)NSArray *cityArr;
@end@implementation rootTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *path=@"http://www.meituan.com/api/v1/divisions?mtt=1.help%2Fapi.0.0.im77fqda";

    NSURL *url=[NSURL URLWithString:path];

    NSData *data=[NSData dataWithContentsOfURL:url];

    XMLDictionaryParser *parser=[[XMLDictionaryParser alloc]init];
    NSDictionary *dic=[parser dictionaryWithData:data];
    self.cityArr=[NSArray arrayWithArray:dic[@"divisions"][@"division"]];

    NSLog(@"%@",self.cityArr);
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuseIdentifier"];

    self.title=@"城市列表";

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
//     self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.cityArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier" forIndexPath:indexPath];

    cell.textLabel.text=self.cityArr[indexPath.row][@"name"];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    secondViewController *sec=[[secondViewController alloc]init];
    sec.location=self.cityArr[indexPath.row][@"location"];
    sec.title=self.cityArr[indexPath.row][@"name"];
    [self.navigationController pushViewController:sec animated:YES];

}

/*// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*//*// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*//*// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*//*// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*//*#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/@end

第二个视图:secondViewController.h

相关图片

相关文章