从网址加载.plist文件 [英] Loading a .plist file from url

查看:72
本文介绍了从网址加载.plist文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,该代码从资源文件夹中加载一个plist文件,并使用它填充表格视图:

I have the following code that loads a plist file from the resource folder and uses it to populate a tableview:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"AnimeDB" ofType:@"plist"]; 
    NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
    self.dataList1 = tmpArray; 
    [tmpArray release];

但是我需要从URL加载此.plist文件. 我尝试了一些在网上找到的解决方案,但无法使其正常运行. 有人知道我该怎么做吗?

But I need to load this .plist file from an url. I tried some solutions that I found on the net, but I couldn't manage to get it working. Does someone know how can i do this?

也许有一个简单的解决方案,但是我刚开始使用xcode(这是我的第一个应用程序),所以我找不到它.

Maybe there's an easy solution, but I'm at the beginning with xcode (this is my first app), so I can't find it.

我们非常感谢您的帮助!

Any help is really appreciated!

P.S.对不起,我可能犯了任何错误,我的英语不好.

P.S. Sorry for any mistake that i may have committed, my english is not that good.

推荐答案

我建议考虑使用 Json .它将使您可以将plist之类的结构化数据从url传递到您的应用.

I suggest looking into using Json. It will allow you to pass plist like structured data from a url to your app.

NSData *dataReturn = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://someUrl.com/test.json"]];

    if (dataReturn) {
        NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:dataReturn options:kNilOptions error:Nil];

如果要使用plist,则其代码几乎相同:

If you want to use your plist then its just about the same code:

// This will get the plist into data format
NSData *dataReturn = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://someUrl.com/test.plist"]];

// This will convert data format to array
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:dataReturn]

这篇关于从网址加载.plist文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆