将 nsstring 数据转换为 nsarray (plist)

发布于 2024-12-21 22:06:59 字数 323 浏览 3 评论 0原文

我想将下载的字符串转换为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦亿 2024-12-28 22:06:59

这不起作用,因为 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 expecting responseString 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文