正在为这个问题苦苦挣扎。想要下载一个只读 plist 以在我的应用程序中使用...
无论如何努力阅读字典中的内容...下面的代码,任何指针都会很棒..
-(void)loadProducts {
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"https://dl.dropboxusercontent.com/s/f1nmq1wa7gs96dp/Region1Products.plist"]];
for (NSDictionary* productDictionary in dict) {
ProductItem* productItem = [[ProductItem alloc] init];
productItem.picturesCount = [productDictionary objectForKey:@"PicturesCount"];
productItem.maxPicturesCount = [productDictionary objectForKey:@"MaxPicturesCount"];
productItem.size = [productDictionary objectForKey:@"Size"];
productItem.previewImageName = [productDictionary objectForKey:@"ImageName"];
productItem.sequence = [productDictionary objectForKey:@"Sequence"];
productItem.productName = [productDictionary objectForKey:@"Name"];
productItem.type = [productDictionary objectForKey:@"ProductType"];
productItem.prices = [productDictionary objectForKey:@"Prices"];
productItem.shippingPrices = [productDictionary objectForKey:@"ShippingPrices"];
productItem.description = [productDictionary objectForKey:@"Description"];
productItem.popupMessage = [productDictionary objectForKey:@"PopupMessage"];
productItem.popupDetailMessage = [productDictionary objectForKey:@"PopupDetailMessage"];
productItem.incrementalPricing = [[productDictionary objectForKey:@"IncrementalPricing"] boolValue];
if (YES == productItem.incrementalPricing) {
productItem.incrementalPrices = [productDictionary objectForKey:@"IncrementalPrices"];
}
NSArray *previewItems = [productDictionary objectForKey:@"PreviewItems"];
for (NSDictionary* previewItem in previewItems) {
[productItem addProductPreviewItemFromDictionary:previewItem];
}
[self.productsList addObject:productItem];
}
最佳答案
您正在从 url 创建 NSDictionary,但该 plist 中的顶级对象是一个数组。要解决这个问题,您可以将 dict 更改为 NSArray 对象。我使用以下简化代码来测试:
NSArray *array = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:@"https://dl.dropboxusercontent.com/s/f1nmq1wa7gs96dp/Region1Products.plist"]];
for (NSDictionary* productDictionary in array) {
NSLog(@"%@",productDictionary);
}
关于iphone - 下载远程 PLIST iOS - 返回 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16749523/