How to extract the following info from NSdictionary?
From the Dictionary, key=key1 value1= {email = "test1@yahoo.com"; firstname = Joe; lastname = Doe; sessionid = "a21ed5ba-5039-11e0-9768-7136bb0a01e4"; "user_type" = 1; }
key=key2 value2={email = "test2@yahoo.com"; 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 j开发者_开发百科ust a simple string.
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.
Here it seems that value1 is again a NSDictionary. So value1 is a dictionary key access the values using respective keys.
[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"];
精彩评论