【发布时间】:2015-02-28 09:22:28
【问题描述】:
我正在使用 CHSV 解析器来解析 csv 文件,但在控制台中什么也没有,下面的代码用于解析 csv。我导入了 CHSV 头文件并提到了CHCSVParserDelegate,即使我也检查了 csv 文件名
CHCSVParser *parser=[[CHCSVParser alloc] initWithContentsOfCSVFile:[NSHomeDirectory() stringByAppendingPathComponent:@"gapunditprogeorgiastatehouse.csv"] delimiter:','];
parser.delegate=self;
[parser parse];
-(void) parserDidBeginDocument:(CHCSVParser *)parser
{
currentRow = [[NSMutableArray alloc] init];
}
-(void) parserDidEndDocument:(CHCSVParser *)parser
{
for(int i=0;i<[currentRow count];i++)
{
NSLog(@"%@ %@ %@",[[currentRow objectAtIndex:i] valueForKey:[NSString stringWithFormat:@"0"]],[[currentRow objectAtIndex:i] valueForKey:[NSString stringWithFormat:@"1"]],[[currentRow objectAtIndex:i] valueForKey:[NSString stringWithFormat:@"2"]]);
}
}
- (void) parser:(CHCSVParser *)parser didFailWithError:(NSError *)error
{
NSLog(@"Parser failed with error: %@ %@", [error localizedDescription], [error userInfo]);
}
-(void)parser:(CHCSVParser *)parser didBeginLine:(NSUInteger)recordNumber
{
dict=[[NSMutableDictionary alloc]init];
}
-(void)parser:(CHCSVParser *)parser didReadField:(NSString *)field atIndex:(NSInteger)fieldIndex
{
[dict setObject:field forKey:[NSString stringWithFormat:@"%d",fieldIndex]];
}
- (void) parser:(CHCSVParser *)parser didEndLine:(NSUInteger)lineNumber
{
[currentRow addObject:dict];
dict=nil;
}
【问题讨论】:
-
你遇到了什么错误.....
-
我对 chsv 解析器一无所获
-
您是否验证了路径正确且不返回nil?
-
你在 [currentRow addObject:dict] 中得到什么结果;
-
是的,我已经验证了路径@boyfarrell,
标签: ios objective-c parsing csv