0

i need to parse the Apple JSON but i have a little problem. I'm now doing this:

The problem is here:

- (void)fetchedData:(NSData *)responseData {
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData
                                                         options:kNilOptions 
                                                           error:&error];



    NSNumber *resultCount = [json objectForKey:@"resultCount"];
    NSLog(@"%i", [resultCount intValue]);

    NSArray * AppStoreUrlParse = [json objectForKey:@"results"]; 

    NSDictionary* StoreParse = [AppStoreUrlParse objectAtIndex:0];

    NSLog(@"%@", [json objectForKey:@"price"]);

}

On this line:

    NSLog(@"%i", [resultCount intValue]);

The NSlog is returing: 1 like in the JSON ( http://itunes.apple.com/lookup?id=387633954)

But on this line

    NSLog(@"%@", [json objectForKey:@"price"]);

The NSLOG returns (Null)

does anyone know how i can get the price from the json?

1 Answer 1

4

It seems that 'price' is part of a dictionary that is the first item in the 'results' array.

Can you try

NSLog(@"%@", [[AppStoreUrlParse objectAtIndex:0] objectForKey:@"price"]);

This would get the value of the key 'price' in the first element of the 'results' array of your JSON.

EDIT

Actually, rereading your code, you are already getting the first element of the array in this line:

NSDictionary* StoreParse = [AppStoreUrlParse objectAtIndex:0];

So all you need to do is change json by StoreParse in your NSLog:

NSLog(@"%@", [StoreParse objectForKey:@"price"]);
Sign up to request clarification or add additional context in comments.

Comments

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.