Search code examples
iosobjective-cios4foursquare

Getting data from NSDictinionary


I'm trying to get the "firstName" , "lastName" , "gender", "homeCity" and "email" from a NSDictionary

but It doesn't work...I have tried the following code:

NSDictionary *userInfo  = [fsUser getUserInfo:@"self"];

NSLog(@"userInfo: %@", userInfo);
NSLog(@"name: %@", [userInfo objectForKey:@"firstName"]);
NSLog(@"lastName: %@", [userInfo objectForKey:@"lastName"]);
NSLog(@"gender: %@", [userInfo objectForKey:@"gender"]);
NSLog(@"homeCity: %@", [userInfo objectForKey:@"homeCity"]);
NSLog(@"email: %@", [userInfo objectForKey:@"email"]);

here is my dictionary value...

  userInfo: {

userDictionary =     {
    meta =         {
        code = 200;
        errorDetail = "Please provide an API version to avoid future errors.See http://bit.ly/vywCav";
        errorType = deprecated;
    };
    notifications =         (
                    {
            item =                 {
                unreadCount = 0;
            };
            type = notificationTray;
        }
    );
    response =         {
        user =             {
            badges =                 {
                count = 0;
                items =                     (
                );
            };
            bio = "";
            checkinPings = off;
            checkins =                 {
                count = 0;
            };
            contact =                 {
                email = "[email protected]";
            };
            firstName = Name;
            following =                 {
                count = 0;
            };
            friends =                 {
                count = 0;
                groups =                     (
                                            {
                        count = 0;
                        items =                             (
                        );
                        name = "Amigos em comum";
                        type = friends;
                    },
                                            {
                        count = 0;
                        items =                             (
                        );
                        name = "Outros amigos";
                        type = others;
                    }
                );
            };
            gender = male;
            homeCity = "";
            id = 3233312;
            lastName = lastName;
            lists =                 {
                groups =                     (
                                            {
                        count = 1;
                        items =                             (
                        );
                        type = created;
                    }
                );
            };
            mayorships =                 {
                count = 0;
                items =                     (
                );
            };
            photo = "https://foursquare.com/img/blank_boy.png";
            photos =                 {
                count = 0;
                items =                     (
                );
            };
            pings = 0;
            referralId = "u-sdsad";
            relationship = self;
            requests =                 {
                count = 0;
            };
            scores =                 {
                checkinsCount = 0;
                goal = 50;
                max = 0;
                recent = 0;
            };
            tips =                 {
                count = 0;
            };
            todos =                 {
                count = 0;
            };
            type = user;
        };
    };
};
   }

Solution

  • Use [userInfo objectForKey:@"userDictionary"] objectForKey:@"response"] objectForKey:@"user"] objectForKey:@"homeCity"].