項目中經常使用到的文件是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);