从 NSDictionary 检索字符串时出现问题

发布于 2024-11-05 03:59:31 字数 1162 浏览 1 评论 0原文

嘿伙计们,我有这段代码:

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

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

发布评论

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

评论(1

当爱已成负担 2024-11-12 03:59:31

试试这个

SJLog(@"lot description from dict: %@ ",[dict objectForKey:@"LOT_DESC"]);

Try this

SJLog(@"lot description from dict: %@ ",[dict objectForKey:@"LOT_DESC"]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文