0

I'm parsing a Json object via AFJSONRequestOperation, the problem is, i cant get the correct value of the node. The Json :

Link

I need to get only the temp value, inside the "results". I can get the results node, but the value inside it come as a array, how i can get the value for the name ?

2 Answers 2

1

That JSON is invalid. Go to this link, and check it.

What Snaker answered is pretty accurate, still:

for (NSDictionary *dic in results)
{
    NSString *name = [dic objectForKey:@"name"];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Crap, looks like my editing wasn't taken into account. But +1
1

Your problem here, is that the results gives you a dictionnary of dictionnaries. So you have to retrieve the dictionnary called "results", and then, once you got all the dictionnaries in it, you look for the names trough a loop.

More information here

UPDATE :

dicionario = [dicionario objectForKey@"results"];
NSMutableArray *namesFromDict = [[NSMutableArray alloc] init];
for (NSDictionary *elts in dicionario)
{
   [namesFromDict addObject:[elts objectForKey:@"name"]];
}

This should do.

2 Comments

Something like this? NSArray * resultados = [[NSArray alloc]initWithArray:[_dicionario objectForKey:@"results"]]; NSMutableDictionary * organizedData = [[NSMutableDictionary alloc] init]; for (NSDictionary * p in resultados) { [organizedData setValue:p forKey:[p valueForKey:@"id"]]; } The count of organizedData return me 20, but when i use NSLog(@"%@",[organizedData objectForKey:@"name"]); gives me null
Well, does [p valueForKey:@"id"] ever return a key called @"name"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.