在 NSDictionary 中使用国际字符时应用程序崩溃

发布于 2024-08-29 07:11:28 字数 836 浏览 2 评论 0原文

我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦欢 2024-09-05 07:11:28

确保 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文