从URL加载NSMutableDictionary [英] Loading NSMutableDictionary from URL

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

问题描述

我正在这样做:

NSMutableDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL: [NSURL URLWithString:@"http://mysite/mypage.php"]];

除了返回的数据相当大以外,哪个是好的,而且似乎超时。如何解决这个问题?

Which is great, apart from when the data being returned is quite large, and it appears to time out. How could I get around this?

提前感谢。

推荐答案

我不是使用NSDictionary管理下载的大粉丝。我可能会尝试像:

I'm not a big fan of using NSDictionary to manage downloads. I'd probably try something like:

NSURL *url = [NSURL URLWithString:@"http://mysite/mypage.php"];
NSURLRequest *request = [NSURLRequest requestWintURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

现在,如果数据不为NULL,则保存到本地文件。然后使用initWithContentsOfFile:方法,使用该文件的内容加载字典。

Now, if data is not NULL then save to local file. Then load the dictionary using the contents of that file using the initWithContentsOfFile: method.

如果仍然可以获得超时,可以尝试更大的timeoutIntervals。

If you still get the timeouts you can try larger timeoutIntervals.

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

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