Get value in NSDictionary

I want to get the value from NSDictionary . I want to manage the "Code" key according to the code of the code, I will get the data values. I get an error message when I try to use 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] * Application termination due to uncaught exception "NSInvalidArgumentException", reason: '- [__ NSArrayM getObjects: andKeys:]: unrecognized selector sent to instance 0x5e138b0' * Call stack on 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" ); }; } ) 
+7
source share
3 answers

You represent an NSArray of NSDictionaries, each of which contains an NSString with a description (Omschrijving) and an NSDictionary (Ophaaldata) with one key (Datum), which is an array of dates. If you send Objects:andKeys: to NSArray, this will not work.

Here are some examples of how you can get individual elements:

 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 just examples of how you can access elements. But this is the structure that your conclusion shows. In any case, everything else would be useless, since the dictionary can contain only each key once. I formatted the code a bit, so you can see the structure a little better.

+10
source

During the response, the value of the lines is taken into account.

 { .......... } 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 
+2
source
 reason: '-[__NSArrayM getObjects:andKeys:]: 

Do you have an NSDictionary , not an NSArray ?

+1
source

All Articles