iphone - CHCSVParser - 如何从网络服务器加载

标签 iphone ios ipad csv ios6

我想从每天更新的网络服务器解析 csv。我正在使用此链接 https://github.com/davedelong/CHCSVParser 中的 csvparser我正在使用这段代码:

 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:'        

我检查了此链接Load remote csv into CHCSVParser它不起作用。我是 ios 新手,请让我知道如何解决这个问题。非常感谢您的帮助。提前致谢。

最佳答案

大概应该是:

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 类方法不是 initWithContentsOfCSVString,而是 initWithCSVString

  • 或者,如果您使用 NSArray 类扩展,则语法为 arrayWithContentsOfCSVStringinitWithContentsOfCSVString;和

  • 您指定了 &encoding 的编码,但此参数不是指针,因此我不知道这怎么可能是正确的;我刚刚指定了编码。

我假设您想使用 NSArray+CHCSVAdditions 类别方法 initWithContentsOfCSVStringarrayWithContentsOfCSVString (它为您提供 autorelease code> 对象),而不是 CHCSVParser,但这取决于您。

关于iphone - CHCSVParser - 如何从网络服务器加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13891301/

相关文章:

iphone - 我现在可以使用新的 Xcode 4.2 开发者预览版来发布常规应用程序吗?

iphone - SBTableAlert 问题。它显示警报但不显示 UITableView

ios - 通过 AFNetworkingLibrary 将 Url 传递给 ImageView

ios - 使用 startMonitoringVisits 监控区域

ios - 在 iPad 上以模态方式呈现 ModalViewController

iphone - 列出 iphone/ipad 上的所有应用程序 URL

iphone - 如何将我的应用以不同的 iPhone/ipad 尺寸上传到 App Store

ios - titleLable.text 不工作

ios - Bloomberg、ABCNews、CBSNews 等新闻 iOS 应用程序如何工作?

ios - 是否可以使用 iOS 以编程方式从我的应用程序在用户的主屏幕上创建快捷图标按钮