将 nsstring 数据转换为 nsarray (plist)
我想将下载的字符串转换为 NSArray。首先,我使用 URLFetcher 下载数据。之后我需要将 plist 数据转换为 nsarray。但未能成功。
-(void)urlDidFinish:(UrlFetcher *)urlFetcher withString:(NSString *) responseString {
NSLog(@"Response: %@", responseString);
data = [NSArray arrayWithContentsOfFile:responseString];
[table reloadData];
}
I would like to convert downloaded string to NSArray. First of all I download data with URLFetcher. After that I need to convert my plist data to nsarray. But could not succeeded.
-(void)urlDidFinish:(UrlFetcher *)urlFetcher withString:(NSString *) responseString {
NSLog(@"Response: %@", responseString);
data = [NSArray arrayWithContentsOfFile:responseString];
[table reloadData];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不起作用,因为 arrayWithContentsOfFile 正在使用字符串作为路径。换句话说,它期望
responseString
是您计算机上的一个文件,而不是包含数据的字符串。也许你可以考虑使用 arrayWithContentsOfURL 来代替,它可能会自动从 URL 获取数据,而不必自己下载,但由于安全限制等原因,我不确定。
您可能对此问题感兴趣:将 Plist (NSString) 解析为 NSDictionary
This isn't working because
arrayWithContentsOfFile
is using the string as a path. In other words, it is expectingresponseString
to be a file on your computer, not a string that contains the data.Perhaps you could consider using
arrayWithContentsOfURL
instead, which might get the data from the URL automatically without having to download it yourself, but I'm not sure due to security restrictions and so on.You might be interested in this question: Parse Plist (NSString) into NSDictionary