You need to do self.infologin[@"Admin"][@"login"]
, because login
is inside the Admin
dictionary.
So first you need to get the Admin
dictionary, and then get login
from that.
Frage
I'm a beginner in ios programming and I found myself having some trouble with Nsdictionnary.
I have a NSdictionnary which looks like this (when I log it like this : NSLog( @"%@", self.infologin );):
{
Admin = {
login = admin;
pass = mdp;
};
}
And I would like to get the value for "login", so I tried many things like :
self.infologin[@"login"];
but I can't find a way to make it work.
If needed, here is the way I get my NSdictionnary :
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.infologin = (NSDictionary *)responseObject;
And here is my Json content :
{"Admin":{"login":"admin","pass":"mdp"}}
Thank you
Lösung
You need to do self.infologin[@"Admin"][@"login"]
, because login
is inside the Admin
dictionary.
So first you need to get the Admin
dictionary, and then get login
from that.