Thursday, 19 September 2013

How to use downloaded JSON object stored in NSArray?

How to use downloaded JSON object stored in NSArray?

I am using SZJsonParser to download JSON object from a site. Here's my code:
#import <Foundation/Foundation.h>
#import "SZJsonParser.h"
int main(int argc, const char * argv[])
{
@autoreleasepool
{
// insert code here...
NSURL *url = [[NSURL alloc]
initWithString:@"http://mymovieapi.com/?title=Cars"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
NSString *str = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSArray *arr = [str jsonObject];
for (int i = 0; i < [arr count]; i ++)
{
NSLog(@"%@",[arr objectAtIndex:i]);
}
}
return 0;
}
When I run the Terminal app, here's the output:
2013-09-19 15:54:49.957 SimpleJSONTerminal[24160:303] {
actors = (
"Owen Wilson",
"Paul Newman",
"Bonnie Hunt",
"Larry the Cable Guy",
"Cheech Marin",
"Tony Shalhoub",
"Guido Quaroni",
"Jenifer Lewis",
"Paul Dooley",
"Michael Wallis",
"George Carlin",
"Katherine Helmond",
"John Ratzenberger",
"Joe Ranft",
"Michael Keaton"
);
"also_known_as" = (
"Cars - Quatre roues"
);
country = (
USA
);
directors = (
"John Lasseter",
"Joe Ranft"
);
genres = (
Animation,
Adventure,
Comedy,
Family,
Sport
);
"imdb_id" = tt0317219;
"imdb_url" = "http://www.imdb.com/title/tt0317219/";
language = (
English,
Italian,
Japanese,
Yiddish
);
"plot_simple" = "A hot-shot race-car named Lightning McQueen gets
waylaid in Radiator Springs, where he finds the true meaning of
friendship and family.";
poster = {
cover =
"http://imdb-poster.b0.upaiyun.com/000/317/219.jpg!cover?_upt=65f114a91379629498";
imdb =
"http://ia.media-imdb.com/images/M/MV5BMTE5Mzk5MTA2Ml5BMl5BanBnXkFtZTYwNTY3NTc2._V1_SY317_CR0,0,214,317_.jpg";
};
rating = "7.3";
"rating_count" = 150431;
"release_date" = 20060822;
runtime = (
"117 min"
);
title = "Cars - Quatre roues\n \"Cars\"";
type = VG;
writers = (
"John Lasseter",
"Joe Ranft"
);
year = 2006;
}
How do I store this in an NSDictionary so that I can use the "title" as a
Key and then get the information ?
Thanks

No comments:

Post a Comment