Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get value in NSDictionary

I want to get value from NSDictionary. I want to control "Code" key according to Code key, I will get datum values. I get error message When I try different methods.

ERROR MESSAGE

2011-08-11 12:45:21.549 AOK[6312:207] -[__NSArrayM getObjects:andKeys:]: unrecognized selector sent to instance 0x5e138b0 2011-08-11 12:45:21.550 AOK[6312:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM getObjects:andKeys:]: unrecognized selector sent to instance 0x5e138b0' * Call stack at first throw:

NSDictionary

(
        {
        Omschrijving = "ADDD";
        Ophaaldata =         {
            Datum =             (
                "2011-07-04",
                "2011-07-11",
                "2011-07-18",
                "2011-07-25"
            );
        };
    },
        {
        Omschrijving = "BBBB";
        Ophaaldata =         {
            Datum =             (
                "2011-07-05",
                "2011-07-12",
                "2011-07-19",
                "2011-07-26"
            );
        };
    },
        {
        Omschrijving = "KKKK";
        Ophaaldata =         {
            Datum =             (
                "2011-07-07",
                "2011-07-14",
                "2011-07-21",
                "2011-07-28"
            );
        };
    },
        {
        Omschrijving = "LLLLL";
        Ophaaldata =         {
            Datum =             (
                "2011-07-01",
                "2011-07-08",
                "2011-07-15",
                "2011-07-22",
                "2011-07-29"
            );
        };
    },
        {
        Omschrijving = "MMMMM";
        Ophaaldata =         {
            Datum =             (
                "2011-07-01",
                "2011-07-15",
                "2011-07-29"
            );
        };
    },
        {
        Code = POP;
        Omschrijving = "FFFF";
        Ophaaldata =         {
            Datum = "2011-07-12";
        };
    },
        {
        Code = 00;
        Omschrijving = "SSSS";
        Ophaaldata =         {
            Datum =             (
                "2011-07-14",
                "2011-07-27"
            );
        };
    },
        {
        Code = 01;
        Omschrijving = "CCCCC";
        Ophaaldata =         {
            Datum =             (
                "2011-07-06",
                "2011-07-20"
            );
        };
    }
)
like image 563
hiwordls Avatar asked Aug 11 '11 09:08

hiwordls


2 Answers

What you display is an NSArray of NSDictionaries, each containing an NSString with the description (Omschrijving) and an NSDictionary (Ophaaldata) with one key (Datum), which is an array of dates. If you send Objects:andKeys: to an NSArray, it won't work.

These are a few examples of how you can get at the individual items:

NSArray          *dicts = ...; // wherever you get the array
  NSDictionary   *mijnDict = [dicts objectAtIndex: n];
    NSString     *omschrijving = [mijnDict objectForKey: @"Omschrijving"];
    NSDictionary *ophaaldata = [mijnDict objectForkey: @"Ophaaldata"];
      NSArray    *datum = [ophaaldata objectForkey: @"Datum"];
        NSString *eersteDatum = [datum objectAtIndex: 0];

These are only examples of how you can address the items. But this is the structure your output shows. Anything else would be useless, anyway, since a dictionary can only contain each key once. I formatted the code a little, so you can see the structure a bit better.

like image 94
Rudy Velthuis Avatar answered Sep 28 '22 02:09

Rudy Velthuis


During Response Value of lines keep in mind

{ .......... } indicates dictionary.
(............) indicates array.
Dictionary always have key with it like somename = "value in it", .......
Array has value seperated by comma like a , b , c .....
Now it is possible it may have array into dictionary like { somekey = ( a,b,c) } and vice versa
like image 45
Paresh Navadiya Avatar answered Sep 28 '22 03:09

Paresh Navadiya