Iphone CHCSVParser-如何从Web服务器加载
我想从每天更新的Web服务器解析csv。我正在使用此链接中的csvparser,我正在使用以下代码:Iphone CHCSVParser-如何从Web服务器加载,iphone,ios,ipad,csv,ios6,Iphone,Ios,Ipad,Csv,Ios6,我想从每天更新的Web服务器解析csv。我正在使用此链接中的csvparser,我正在使用以下代码: NSError *err = [[[NSError alloc] init] autorelease]; NSString *lunchFileURL = [[NSString stringWithFormat:@"http://www.somewhere.com/LunchSpecials.csv"] stringByAddingPercentEscapesUsingEncoding:NSU
NSError *err = [[[NSError alloc] init] autorelease];
NSString *lunchFileURL = [[NSString stringWithFormat:@"http://www.somewhere.com/LunchSpecials.csv"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *lunchFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:lunchFileURL] encoding:NSUTF8StringEncoding error:&err];
CHCSVParser *p = [[CHCSVParser alloc] initWithContentsOfCSVString:lunchFile usedEncoding:&encoding error:nil];
我得到这个错误: No visible @interface for 'CHCSVParser' declares the selector 'initWithContentsOfCSVString:usedEncoding:error:'
我检查了此链接,但它不起作用。我是ios的noob,请告诉我如何修复此问题。非常感谢您的帮助。提前感谢。可能是:
NSError *err;
NSString *lunchFileURL = [[NSString stringWithFormat:@"http://www.somewhere.com/LunchSpecials.csv"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *lunchFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:lunchFileURL]
encoding:NSUTF8StringEncoding
error:&err];
// if you're going to create a CHCSVParser yourself, the syntax is:
CHCSVParser *p = [[CHCSVParser alloc] initWithCSVString:lunchFile
encoding:NSUTF8StringEncoding
error:&err];
// or, if you're going to use NSArray+CHCSVAdditions.h, the syntax might be:
NSArray *array = [[NSArray alloc] initWithContentsOfCSVString:lunchFile
encoding:NSUTF8StringEncoding
error:&err];
注:
- 你不需要
/alloc
这个init
对象;这些接受NSError
参数的类将在遇到错误时为您创建自动释放错误对象;否则他们就别管它了NSError**
类方法不是CHCSVParser
,而是initwithcontentsofsofcsvstring
initWithCSVString
- 或者,如果使用
类扩展,则语法为NSArray
或arrayWithContentsOfCSVString
;及initWithContentsOfCSVString
- 您指定了
的编码,但此参数不是指针,因此我不认为这可能是正确的;我刚刚指定了编码&encoding
我假设您想使用
NSArray+CHCSVAdditions
类别方法initwithcontentsofsofcsvstring
或arraywhithcontentsofsofcsvstring
(它为您提供了一个autorelease
对象),而不是CHCSVParser
,但这取决于您。感谢Sachin的编辑。仅供参考,我用两个例子更新了我的答案。总之,initWithContentsOfCSVString
是一个NSArray
分类方法,而不是CHCSVParser
方法。这是有史以来最好的答案。非常感谢Rob。太棒了!!