iOS xml文件转字典

项目中经常使用到的文件是json数据,或者是plist文件,但若是产品给你是xml文件呢,若是文件很大,你修改为plist文件或Json文件很麻烦,下面介绍个人方法git

 其实用第三方的一个库几行代码就能够解决github

第三方库名称:XMLReader,你能够去github上进行下载https://github.com/amarcadet/XMLReader json

下载完成后只需拖入XMLReader.h和XMLReader.m文件便可spa

下面就是开始转换了
code

  //找到所需转换的xml文件路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"suoyou" ofType:@"xml"];
    NSData *data = [[NSData alloc] initWithContentsOfFile:path];
    NSError *error = nil;
    NSDictionary *dic = [XMLReader dictionaryForXMLData:data options:XMLReaderOptionsProcessNamespaces error:&error];
    NSLog(@"%@", dic);
相关文章
相关标签/搜索