IOS NSDictionary问题

时间:2013-10-30 11:23:33

标签: ios objective-c ios6 nsdictionary

我有一个NSDictonary看起来像

{
    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";
        }
    );
}

我想将这三个变量(nowshowing,slideShowImages,programmecategory)分开在我的程序中是否有一种方法可以让任何身体告诉我该怎么做,我是IOS开发新手我不知道该怎么做谢谢

4 个答案:

答案 0 :(得分:1)

您使用此方法:

[dictionary objectForKey:@"key"];

“key”可以是:“nowShowing”,“programmeCategory”或“slideShowImages”

答案 1 :(得分:1)

NSArray *program = [myDictionary objectForKey:@"programmeCategory"];

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

[program objectAtIndex:0]

答案 2 :(得分:1)

您可以使用以下方式获得:

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

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

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

答案 3 :(得分: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"];
    }