从 NSDictionary 检索字符串时出现问题
嘿伙计们,我有这段代码:
SJLog(@"dict: %@",dict);
打印这本字典:
2011-05-04 02:37:51.537 Parking[14458:207] dict: {
"A_SPACES" = 0;
"DP_SPACES" = 7;
"LOT_DESC" = "West of the Maddy Lab off of West Health Science Dr.";
"LOT_ID" = 44;
"LOT_NAME" = LOT57;
"L_SPACES" = 0;
"MC_SPACES" = 8;
"VISITOR_SPACES" = 263;
"permits_accepted" = {
A = 1;
C = 1;
L = 0;
};
}
我试图通过以下代码检索 LOT_DESC 的值:
SJLog(@"lot description from dict: %@ ",[dict objectForKey:@"@LOT_DESC"]);
但我得到了这个:
2011-05-04 02:37:51.537 Parking[14458:207] lot description from dict: (null)
如果我使用 [dict valueForKey:@"@LOT_DESC" ]
我收到以下错误:
2011-05-04 02:44:28.148 Parking[14505:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFDictionary 0x58c8660> valueForUndefinedKey:]: this class is not key value coding-compliant for the key LOT_DESC.'
通过 valueForKey
访问字典以获取所有数值都可以正常工作。所以,我不知道出了什么问题,并且真的很想得到一些建议。提前致谢!
Hey guys, so I have this code:
SJLog(@"dict: %@",dict);
That prints this dictionary:
2011-05-04 02:37:51.537 Parking[14458:207] dict: {
"A_SPACES" = 0;
"DP_SPACES" = 7;
"LOT_DESC" = "West of the Maddy Lab off of West Health Science Dr.";
"LOT_ID" = 44;
"LOT_NAME" = LOT57;
"L_SPACES" = 0;
"MC_SPACES" = 8;
"VISITOR_SPACES" = 263;
"permits_accepted" = {
A = 1;
C = 1;
L = 0;
};
}
And I am trying to retrieve the value for LOT_DESC via the following code:
SJLog(@"lot description from dict: %@ ",[dict objectForKey:@"@LOT_DESC"]);
But I get this:
2011-05-04 02:37:51.537 Parking[14458:207] lot description from dict: (null)
And if I use [dict valueForKey:@"@LOT_DESC"]
I get the following error:
2011-05-04 02:44:28.148 Parking[14505:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFDictionary 0x58c8660> valueForUndefinedKey:]: this class is not key value coding-compliant for the key LOT_DESC.'
Accessing the dictionary via valueForKey
for all numeric values works fine. So, I have no idea what is going wrong and would really love some advice. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
Try this