我有一個包含數組和字典的.plist文件。我想將其轉換爲CSV文件,然後我可以將它在線上傳到數據庫。有誰知道一個簡單的方法來做到這一點?將plist轉換爲CSV文件?
1
A
回答
2
戴夫·德隆已經寫了一個CSV解析器,這將幫助你完成這個任務,就可以得到這個答案,他已經張貼在這個問題的詳細信息... How to convert the NSMutableArray to CSV file on iPhone?
4
請看下面的代碼
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];
NSArray *commentArray = [NSArray arrayWithContentsOfFile:plistPath];
NSMutableString *mainString=[[NSMutableString alloc]initWithString:@""];
for(int i=0;i<[commentArray count];i++) {
NSString *string=[[commentArray objectAtIndex:i]objectForKey:@"cmtName"];
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""];
[mainString appendFormat:@"\"%@\"",string];
string=[[commentArray objectAtIndex:i]objectForKey:@"cmtDesc"];
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""];
[mainString appendFormat:@",\"%@\"",string];
string=[[commentArray objectAtIndex:i]objectForKey:@"cmtType"];
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""];
[mainString appendFormat:@",\"%@\"",string];
[mainString appendFormat:@",\"%@\"",string];
[mainString appendFormat:@"\n"];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:@"Docment.conf"];
NSData* settingsData;
settingsData = [mainString dataUsingEncoding: NSASCIIStringEncoding];
if ([settingsData writeToFile:filePath atomically:YES])
NSLog(@"writeok");
您也可以使用https://github.com/davedelong/CHCSVParser來生成CSV。
相關問題
- 1. 如何將plist文件轉換爲csv文件? (XCODE)
- 2. 將NSString從plist文件轉換爲NSURL
- 3. 將對象轉換爲plist文件再轉換爲數據
- 4. 將.csv文件轉換爲.xls文件
- 5. 將.xls文件轉換爲.csv文件?
- 6. 將MS文檔轉換爲csv文件
- 7. 將csv轉換爲文本
- 8. 將JSON轉換爲.plist
- 9. PHP - 將JSON轉換爲Plist?
- 10. 將.csv轉換/分析爲xlsx文件
- 11. 將csv文件轉換爲字典
- 12. Python - 將csv文件轉換爲JSON
- 13. 如何將HSSFWorkbook轉換爲CSV文件..?
- 14. 將csv文件轉換爲xlsx
- 15. 將CHM文件轉換爲CSV或SQL
- 16. 將xls文件批量轉換爲csv
- 17. 將Oracle .dmp文件轉換爲CSV/TSV
- 18. 將CSV轉換爲MYSQL文件
- 19. Perl:將csv文件轉換爲xml
- 20. 將.log文件轉換爲CSV格式
- 21. 將csv文件轉換爲python字典
- 22. 如何將.rpt文件轉換爲csv
- 23. 將CSV文件轉換爲XML
- 24. 將mdb文件轉換爲csv
- 25. 上傳文件,將csv轉換爲html
- 26. 將哈希轉換爲csv文件
- 27. 將XML文件轉換爲CSV
- 28. 從.dta(stata)將文件轉換爲.csv
- 29. 將CSV文件轉換爲TF記錄
- 30. 將JavaBean轉換爲CSV文件