您的位置:首页 > 理论基础 > 计算机网络

网络:Plist 解析

2016-04-07 15:54 393 查看
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self locolPlist];
}

// 本地的plist 文件
- (void)locolPlist {
// 路径
NSString *path = [[NSBundle mainBundle]pathForResource:@"videos.plist" ofType:nil];

// 数组
NSArray *data = [NSArray arrayWithContentsOfFile:path];

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

// 网络的plist文件
// plist解析了解一下就可以
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// NSURL
NSURL *url = [NSURL URLWithString:@"http://localhost/videos.plist"];

// 创建请求
NSURLRequest *request = [NSURLRequest requestWithURL:url];

// 发送异步
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
//        NSLog(@"%@",data);
//        NSJSONSerialization
// 解析plist 文件
id result = [NSPropertyListSerialization propertyListWithData:data options:0 format:NULL error:NULL];
//        NSLog(@"%@",result);
}];
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: