0

我在这里检查了许多关于从我的服务器下载 plist 文件并将其转换为可用的 NSDictionary 的问题。无论出于何种原因,当我NSLogNSDictionaryplist 文件创建时,我在控制台中得到了这个:

Timestamp: (null)

我知道这是一个真实的文件: http: //www.faithlifefellowship.us/iOS/sermons.plist

代码:

NSDictionary* plist = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"http://www.faithlifefellowship.us/iOS/sermons.plist"]];

NSLog(@"%@",plist);

问题是什么?

这可能与 plist 文件被缩小这一事实有关吗?

更新:

使用以下代码获取文件:

NSString* pl = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.faithlifefellowship.us/iOS/sermons.plist"] encoding:NSUTF8StringEncoding error:nil];

NSLog(@"%@",pl);

返回:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>1</key><array><integer>1</integer><string>I've Been Redeemed</string><string>Ive Been Redeemed</string><array><string></string></array><array><string>03/20/09</string><string>04/02/09</string><string>04/10/09</string><string>04/24/09</string><string>05/13/09</string><string>05/23/09</string><string>06/06/09</string><string>06/13/09</string><string>06/20/09</string></array><string>http://faithlifefellowship.us/Sermons/Banners/Banner-IBR.png</string><integer>9</integer><array><string>Many Christians allow things in their lives, not realizing that they have been redeemed from them and because of ignorance of God's Word, do not walk in total freedom. This series will set you free in every area of your life!</string><string>It is important to be able to differentiate between a curse in our lives and suffering tribulation for the Lord's sake.</string><string>The same exact blessing that was on Abraham's life is now on our lives because of Jesus Christ. Don't let ignorance or unbelief keep you from all that God has for you!</string><string>Well, I guess God wants me to be sick to teach me a lesson, ever heard someone say that? Well that does not work EVER in the light of God's Word. Gal 3:13 Christ HAS redeemed us...</string><string>As we age the world says that we get weaker mentally, but God's Word does not agree with this. Part of what we have been redeemed from is an unsound and unstable mind.</string><string>Get up early, work late, still nothing ever seems to go your way why? Becasue of the curse. The Good News is that we have been redeemed from loss and failure in our lives!</string>

等等等等等等……都在那里

4

1 回答 1

4

此文件中有未转义的 & 符号(即 ' Pt 1 & 2'),这是受限制的。您应该在您的服务器上替换它们&amp;,或者将文件的内容下载到 NSString 然后替换&&amp;

NSString *error;
NSString *str = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.faithlifefellowship.us/iOS/sermons.plist"]
                                         encoding:NSUTF8StringEncoding
                                            error:&error];

str = [str stringByReplacingOccurrencesOfString:@" & " withString:@" &amp; "];
NSData *plistData = [str dataUsingEncoding:NSUTF8StringEncoding];

NSPropertyListFormat format;
NSDictionary *plist = [NSPropertyListSerialization propertyListFromData:plistData
                                                       mutabilityOption:NSPropertyListImmutable 
                                                                 format:&format 
                                                       errorDescription:&error];

另外,标签匹配存在很大问题。您可以使用http://www.xmlvalidation.com验证您的 plist

于 2013-02-13T17:09:34.493 回答