我正在尝试创建一个NSMutableDictionary,并用从我的网站上查询到的论坛帖子填充它。超级简单的代码,除了..。
_postBodies = [[NSMutableDictionary alloc] initWithContentsOfURL:[NSURL URLWithString:urlBodiesSource]];...pulling从一个PHP/MySQL生成的plist文件,它通常工作得很好。问题是,如果任何帖子包含某些字符,例如非英语字母或HTML符号等,整个过程将无法完全初始化。我在调试器中逐行跟踪它,我可以在源文件中的34个帖子(或其他任何内容)中看到它工作,但将带有奇怪字符的第35个帖子添加到plist中,整个事情都无法初始化。
有什么办法可以解决这个问题吗?剥离或转义对NSMutableDictionary有问题的字符的一些方法?或者可能是他们弄错了我的plist文件,而字典工作得很好?
例如,查看this plist source file。它只有三个帖子长,最后一个是问题所在。排除这篇帖子,整个事情都可以工作;包括它,NSMutableDictionary根本无法填充。这看起来很正常,除了它有一些标签和一些带外折的O。
<key>2</key>
<string>Wow, SquattingB.  I know I'm melodramatic, but what's with you?  lol.  Yeah, it's a shame that all the cool people congregated here just to watch the codex, only to have the series end and leave everyone dumbstruck as to what to do.  (It was that good, nothing else has the same appeal)  Hopefully this forum will remain as cool as it has been up to the point when the creators get out of college.  Then maybe we can see whether they have awesome news of what is next for the series and the forum or if they just boot us back to HBO.  lol.But what is a forum?Dictionary   forum |?fôr?m| noun ( pl. forums ) 1 a place, meeting, or medium where ideas and views on a particular issue can be exchanged : it will be a forum for consumers to exchange their views on medical research. 2 a court or tribunal. 3 ( pl. fora |?fôr?|) (in an ancient Roman city) a public square or marketplace used for judicial and other business. ORIGIN late Middle English (sense 3) : from Latin, literally ‘what is out of doors,’ originally denoting an enclosure surrounding a house; related to fores ‘(outside) door.’ Sense 1 dates from the mid 18th cent.That's what I thought.  So the people are what make it great, yes?  And I'm sure the patrons aren't leaving anytime soon, so we're in pretty good standing as to what will become of the forum.  For now, anyway.</string>以前有没有人经历过这种情况,或者有人能给出一些建议吗?我只是刚刚开始,所以更简单的解决方案将不胜感激,但我喜欢你能提供的任何见解!
发布于 2013-05-22 10:30:50
您正在检查PList文本编码吗?请记住,iOS编程是用UTF8完成的。
我假设(因为问题是用PHP标记的),您正在检索的URL适用于PHP。您是否尝试过使用utf8_encode()对文本进行编码
另一种方法是使用JSON。PHP中的json_encode()会自动将奇怪的字符转换为其UTF8十六进制表示(\x{})。此外,您还可以尝试使用htmlspecialchars().
祝好运!
https://stackoverflow.com/questions/16682242
复制相似问题