从NSDictionary中提取信息

时间:2012-08-02 20:23:17

标签: objective-c ios nsdictionary

我有来自Flickr api请求的NSDictionary响应,它的描述如下:

self.userInfo: {
"_text" = "\n\n";
person =     {
    "_text" = "\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n";
    description =         {
    };
    iconfarm = 0;
    iconserver = 0;
    id = "83943196@N02";
    ispro = 0;
    location =         {
    };
    "mbox_sha1sum" =         {
        "_text" = 7b61c5d24f12345678be82c31234567830540;
    };
    mobileurl =         {
        "_text" = "http://m.flickr.com/photostream.gne?id=12345678";
    };
    nsid = "12345678@N02";
    "path_alias" = "";
    photos =         {
        "_text" = "\n\t\t\n\t\t\n\t\t\n\t\t\n\t";
        count =             {
            "_text" = 2;
        };
        firstdate =             {
            "_text" = 12345678;
        };
        firstdatetaken =             {
            "_text" = "2012-08-01 12:46:38";
        };
        views =             {
            "_text" = 0;
        };
    };
    photosurl =         {
        "_text" = "http://www.flickr.com/photos/12345678@N02/";
    };
    profileurl =         {
        "_text" = "http://www.flickr.com/people/12345678@N02/";
    };
    realname =         {
        "_text" = "Me TheUser";
    };
    timezone =         {
        label = "Pacific Time (US & Canada); Tijuana";
        offset = "-08:00";
    };
    username =         {
        "_text" = metheuser;
    };
};
stat = ok;
}

我正在使用truoble搞清楚如何将realname值提取到NSString中。

我试过了:

NSString * temp = [self.userInfo valueForKey:@"realname"];
NSLog (@"FL: nameOfSignedInUser. nameself.userInfo: %@", temp.debugDescription);

但是回复为零。

谢谢你!

2 个答案:

答案 0 :(得分:1)

NSString *name = [self.userInfo valueForKeyPath:@"person.realname._text"];

答案 1 :(得分:0)

NSString *realName = [[[self.userInfo objectForKey:@"person"] objectForKey:@"realname"] objectForKey:@"_text"];