NSMutableDictionary objectForKey使用正确的密钥返回null

时间:2016-09-13 00:28:43

标签: objective-c nsmutabledictionary

我对NSDictionary有一个非常奇怪的问题,看看代码和控制台输出,看看你自己。

for (int y = 0; y < self.tileProperties.allKeys.count; ++y) {

//I go over all the keys in my NSDictionary,self.tileProperties.

       NSString *string = [self.tileProperties.allKeys objectAtIndex:y];

        NSLog(@"Keys is %@",string);
        NSLog(@"Objects in Array %@",[self.tileProperties objectForKey:string]);
    }


   NSLog(@"Object in Array 2 %@",[self.tileProperties objectForKey:@"496"]);

这是控制台输出的内容。

2016-09-12 17:23:00.822 GreatGrimBeta[1043:130572] Keys is 496
2016-09-12 17:23:00.822 GreatGrimBeta[1043:130572] Objects in Array {
fire = 7;
}
2016-09-12 17:23:00.823 GreatGrimBeta[1043:130572] Object in Array 2 (null)

为什么我从for循环中使用的相同键中获取null?

谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

JoshCaswell帮助下的答案

results: [
{
    list_name: "E-Book Fiction",
    display_name: "E-Book Fiction",
    bestsellers_date: "2016-09-03",
    published_date: "2016-09-18",
    rank: 1,
    rank_last_week: 0,
    weeks_on_list: 1,
    asterisk: 0,
    dagger: 0,
    amazon_product_url: "http://www.amazon.com/Great-Reckoning-Novel-Inspector-Gamache/dp/1250022134?tag=thenewyorktim-20",
isbns: [],
    book_details: [
    {
        title: "A GREAT RECKONING",
        description: "An instructor at the police academy is found murdered, perhaps by one of the cadets favored by Armand Gamache, the retired homicide chief of the Sûreté du Québec.",
        contributor: "by Louise Penny",
        author: "Louise Penny",
        contributor_note: "",
        price: 0,
        age_group: "",
        publisher: "Minotaur",
        primary_isbn13: "9781250022127",
        primary_isbn10: "1250022126"
    }
    ],
    reviews: [
    {
        book_review_link: "",
        first_chapter_link: "",
        sunday_review_link: "",
        article_chapter_link: ""
    }
]
}