在 NSDictionary 中使用国际字符时应用程序崩溃
我从 plist
文件中将数据列出到 UITableView,其中有一个二维数组/字典:(
<?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">
<array>
<dict>
<key>ID</key>
<integer>1</integer>
<key>Title</key>
<string>Middelthunsgate</string>
<key>Description</key>
<string>Vis-a-vis nr 21, retning Kirkeveien</string>
</dict>
</array>
</plist>
如果您想知道,这是挪威语的。)这工作正常,直到我开始使用一些特殊的挪威字符,如 æøå 等。该应用程序构建时没有错误,但它崩溃了。我发现这是因为我使用了字符 ø
和 é
作为 Title
键的字符串。当我删除那本字典时,它又运行得很好。
我该怎么做才能确保即使使用 i18n 字符也能正常读取?
I am listing out data to a UITableView from a plist
file where I have a two dimensional array/dictionary:
<?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">
<array>
<dict>
<key>ID</key>
<integer>1</integer>
<key>Title</key>
<string>Middelthunsgate</string>
<key>Description</key>
<string>Vis-a-vis nr 21, retning Kirkeveien</string>
</dict>
</array>
</plist>
(In case you're wondering, this is in Norwegian.) This works fine, until I start using some special Norwegian characters like æøå etc. The app builds without errors, but it crashes. I found out it was because I used the characters ø
and é
as the string for the Title
key. When I removed that dictionary, it ran just fine again.
What can I do to make sure it reads fine, even with i18n characters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保 plist 保存为 UTF-8 编码,而不是 MacRoman。
使用“属性列表编辑器”(iPhone SDK附带),这样您就不需要关心编码。
Make sure the plist is saved as UTF-8 encoding, instead of MacRoman.
Use the "Property List Editor" (comes with the iPhone SDK) so that you don't need to care about encodings.