带有@ 符号的 NSDictionary 键 [英] NSDictionary keys with @ symbol

查看:55
本文介绍了带有@ 符号的 NSDictionary 键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像之前在这里问过的在 NSDictionary 上使用 valueForKeyPath 如果一个键开始@符号?

如果我必须将 NSDictionary 与诸如@ID"和@Name"之类的键一起使用(服务器端限制,我无法控制命名),我该如何解决?现在,每次我尝试访问此类密钥时,该应用都会崩溃.

If i have to use NSDictionary with keys like "@ID" and "@Name" (Server side limitations,I have no control over the naming) how can i work around that? Right now the app just crash every time I'm trying to access to this kind of keys.

推荐答案

如前所述,您不能这样做.释义 Apple Docs reg.密钥格式 -

As already stated you cannot do this. To Paraphrase Apple Docs reg. Key format -

键必须使用 ASCII 编码,以小写字母开头,并且可以不包含空格.

Keys must use ASCII encoding, begin with a lowercase letter, and may not contain whitespace.

因此,尝试使用 @.. 作为开始的键并不会切断它.我建议您这样做 - 由于您无法更改后端发送密钥的方式,因此您可以控制这些密钥在 iOS 中的表示方式.因此,一旦您获得密钥,请删除起始 @ 符号并插入字符串的其余部分作为密钥.由于 @ 在所有键中都是不变的,因此从所有键中删除它们不应影响您的 dict 的基数.

So trying to have a key with @.. as start isn't going to cut it. What I suggest you do is this - since you cannot change the way your backend sends the keys, you can control how those keys are represented in iOS. So Once you get the keys remove the starting @ symbol and insert the rest of the string as key. Since @ is constant across all keys, removing them from all keys should not affect cardinality of your dict.

这篇关于带有@ 符号的 NSDictionary 键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆