简体   繁体   English

将plist从URL读入NSMutableDictionary

[英]Read plist from URL into NSMutableDictionary

I am trying to do read a PLIST from URL to a NSMutableDictionary. 我正在尝试从URL读取PLIST到NSMutableDictionary。

Code before 之前的代码

autos = [[NSMutableArray alloc] init];

[autos addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Auto 1", @"name", @"Auto.png", @"image", @"Klassiker", @"description" , nil]];

This works. 这可行。 But now I want to use a PLIST. 但是现在我想使用一个PLIST。 And I am trying this, this way: 我正在这样尝试:

autos = [[NSMutableArray alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://dl.dropbox.com/u/9358444/auto.plist"]]];

Thanks. 谢谢。

PLIST http://dl.dropbox.com/u/9358444/auto.plist PLIST http://dl.dropbox.com/u/9358444/auto.plist

Your property list contains a dictionary, but you're trying to use it to instantiate an array. 您的属性列表包含一个字典,但是您试图使用它来实例化数组。 Do this instead: 改为这样做:

NSMutableDictionary *autos = [[NSMutableDictionary alloc] initWithContentsOfURL:
                                 [NSURL urlWithString:@"http://dl.dropbox.com/u/9358444/auto.plist"]];

I'm new to the site, I'm still not sure how to add comments to the OP. 我是该网站的新手,我仍然不确定如何在OP中添加评论。 Load it into a dictionary first then transfer it into a mutable array 首先将其加载到字典中,然后将其传输到可变数组中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM