lilzz
lilzz

Reputation: 5413

How to extract the following info from NSdictionary?

From the Dictionary, key=key1 value1= {email = "[email protected]"; firstname = Joe; lastname = Doe; sessionid = "a21ed5ba-5039-11e0-9768-7136bb0a01e4"; "user_type" = 1; }

key=key2 value2={email = "[email protected]"; firstname = Dan; lastname = Smith; sessionid = "a20ed5ba-7039-21e0-6868-7136bb0a01e4"; "user_type" = 2; }

in other word, the value for key1 is bunch of info , not just a simple string.

Upvotes: 0

Views: 546

Answers (3)

Vaibhav Tekam
Vaibhav Tekam

Reputation: 2344

Let the value be an array or object of user defined class.

@interface User : NSObject
{
NSString * email, * firstName, * lastName, * sessionId;
int userType;
}

you can create object of this class and insert it as a key-value pair in NSDictionary. And retrieve it back.

User * user = [dict objectForKey:key1];

Or you can insert a NSDictionary in a NSDictionary object and retrieve the values.

NSDictionary * dict1 = [dict objectForKey:key1];
NSString * email = [dict1 objectForKey:@"email"];

Hope this helps.

Upvotes: 1

visakh7
visakh7

Reputation: 26390

[dict objectForKey:key1]; will give you another NSDictionary. 

So if you want to access e-mail from first dictionary with key as key1 you can try

[[dict objectForKey:key1] objectForKey:@"email"];

Upvotes: 0

YPK
YPK

Reputation: 1851

Here it seems that value1 is again a NSDictionary. So value1 is a dictionary key access the values using respective keys.

Upvotes: 0

Related Questions