我正在使用 CHCSVParser 在 iPhone 上解析 CSV。如果我不将字段包装在 CSV 中,它就可以正常工作。除了我不能在字段中使用逗号!但是,如果我使用引号,它不会导入任何内容。 失败的 CSV 示例:
"Myotis", "distribution-myotis.png", "myotis description"
"Bbar", "bbar-distribution.png", "bbar description"
"Lesser Horseshoe", "distribution-lesser-horsehoe.jpg", "LH description"
代码:
NSString *CSVfile = [[NSBundle mainBundle] bundlePath];
CSVfile = [CSVfile stringByAppendingString:@"/batDB.csv"];
_batDB = [NSArray arrayWithContentsOfCSVFile:CSVfile options:CHCSVParserOptionsSanitizesFields];
NSLog(@"%@", _batDB);
此记录为空。如果没有引号,它会正确地将 CSV 文件中的内容记录在数组中。
有什么想法吗?!
最佳答案
唉....通过反复试验解决了它,我在逗号后面多了一个空格。即 ", "
而不是 ","
关于ios - 使用 CH CSVParser 解析引用的 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17805561/