从NSDictionary检索字符串的问题

时间:2011-05-04 09:49:28

标签: iphone cocoa-touch 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访问所有数值的字典工作正常。所以,我不知道出了什么问题,真的很喜欢一些建议。提前谢谢!

1 个答案:

答案 0 :(得分:2)

试试这个

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