如何从NSDictionary获取密钥对象? [英] How to get object for key from NSDictionary?

查看:70
本文介绍了如何从NSDictionary获取密钥对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在名为 dict 的词典中,键值对是:

In dictionary named dict the key value pair is:


alba \ U2019s window=westindies中的模型。;

"alba\U2019s window" = "A model in westindies.";

并发送 objectForKey:我得到的字符串就像alba的窗口。当我发送如下内容时:

And to send objectForKey: I am getting the string like "alba's window". When I send like following:


[dict objectForKey:alba的窗口];

[dict objectForKey:alba's window];

我没有得到任何东西,它显示为空。

I am not getting anything, it is showing null.

推荐答案

对于初学者,你可能会想要使它成为一个实际的字符串,如下所示:

For starters, you might want to make that an actual string, like so:

[dict objectForKey:@"alba's window"];

另请注意 \ U2019 不是 ;但',完全是另一个角色。

Note also that \U2019 is not '; but , which is a different character entirely.

更一般地说,坚持字典键的[a-zA-Z0-9] + 可能是一个好主意,除非您使用与键完全相同的字符串以编程方式插入和检索。

And more generally, sticking to [a-zA-Z0-9]+ for dictionary keys is probably a good idea, unless you are inserting and retrieving programmatically using the exact same string as a key.

这篇关于如何从NSDictionary获取密钥对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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