-5

我有一个 NSDictionary 看起来像

{
    nowShowing =     (
        {
            programmeName = xx;
        },
        {
            programmeName = xx;
        },
        {
            programmeName = xx;
        }
    );
    programmeCategory =     (
        {
            imageUrl = "xx";
            programmeDescription = "xx";
            programmeName = xx;
        },
        {
            imageUrl = "xx";
            programmeDescription = "xx";
            programmeName = "xx";
        },
        {
            imageUrl = "xx";
            programmeDescription = "xx";
            programmeName = "xx";
        }
    );
    slideShowImages =     (
        {
            imageLink = "xx";
        },
        {
            imageLink = "xx";
        },
        {
            imageLink = "xx";
        },
        {
            imageLink = "xx";
        }
    );
}

我想在我的程序中单独获取这 3 个变量(nowshowing、slideShowImages、programcategory)有没有办法任何人告诉我如何做到这一点,我是 IOS 开发的新手,我不知道如何做到这一点谢谢

4

4 回答 4

1

您使用此方法:

[dictionary objectForKey:@"key"];

其中“key”可以是:“nowShowing”、“programmeCategory”或“slideShowImages”

于 2013-10-30T11:25:58.147 回答
1
NSArray *program = [myDictionary objectForKey:@"programmeCategory"];

对其他两个做同样的事情。这样,您就有了一个包含该对象的所有项目的数组,您可以像这样引用每个项目:

[program objectAtIndex:0]
于 2013-10-30T11:29:06.067 回答
1

您可以通过以下方式获得它:

NSArray *nowShowing = [dictionary objectForKey:@"nowShowing"];

NSArray *programmeCategory = [dictionary objectForKey:@"programmeCategory"];

NSArray *slideShowImages = [dictionary objectForKey:@"slideShowImages"];
于 2013-10-30T11:29:58.450 回答
1

可以这样访问…………

NSArray *nowShowingArray,*programCategoryArray,*slideShowImagesArray; //Dont forget to alloc i havent done here
    nowShowingArray=[mainDict valueForKey:@"nowShowing"]; //these are array of dictionaries
    programCategoryArray=[mainDict valueForKey:@"programCategory"];
    slideShowImagesArray=[mainDict valueForKey:@"slideShowImages"];

    for (NSDictionary *object in nowShowingArray)
    {
        NSString *name=[object valueForKey:@"programmeName"];  //acess each like this
    }
    for (NSDictionary *object in programCategoryArray)
    {
        NSString *name,*imageUrl,*programDescription;
        imageUrl=[object valueForKey:@"imageUrl"];
        name=[object valueForKey:@"programName"];                         //acess each like this
        programDescription=[object valueForKey:@"programDescription"];
    }
    for (NSDictionary *object in slideShowImagesArray)
    {
        NSString *imageLink=[object valueForKey:@"imageLink"];
    }
于 2013-10-30T11:38:43.223 回答