我正在尝试创建一个 NSMutableDictionary 并使用从我的网站查询的论坛帖子填充它。超级简单的代码,不过...
_postBodies = [[NSMutableDictionary alloc] initWithContentsOfURL:[NSURL URLWithString:urlBodiesSource]];
...从 PHP/MySQL 生成的 plist 文件中提取,通常效果很好。问题是,如果任何帖子包含某些字符,例如非英文字母或 HTML 符号等,则整个事情都无法完全初始化。我已经在调试器中逐行跟踪它,我可以从字面上看到它与源文件中的 34 个帖子(或其他)一起工作,但是将带有奇怪字符的第 35 个帖子添加到 plist 中,整个事情都失败了初始化。
有没有解决的办法?一些剥离或转义对 NSMutableDictionary 有问题的字符的方法?或者他们可能会绊倒我的 plist 文件,而 Dictionary 工作正常吗?
例如,查看这个 plist 源文件。才三个帖子长,最后一个是问题。排除那个帖子,整个事情都有效;包含它并且 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>
有没有人经历过这种情况,或者任何人都可以提供任何建议吗?我刚刚开始,所以更简单的解决方案将不胜感激,但我希望你能提供任何见解!