Skip to content

Instantly share code, notes, and snippets.

@pratikshabhisikar
Created February 23, 2012 11:23
Show Gist options
  • Save pratikshabhisikar/1892445 to your computer and use it in GitHub Desktop.
Save pratikshabhisikar/1892445 to your computer and use it in GitHub Desktop.
NSString *jsonString = @"{\
\"posts\" : [\
{\
\"post\" : {\
\"description\" : \"The latest news from the Joomla! Team\",\
\"id\" : \"1\",\
\"title\" : \"Latest\"\
}\
},\
{\
\"post\" : {\
\"description\" : \"A selection of links that are all related to the Joomla! Project.\",\
\"id\" : \"2\",\
\"title\" : \"Joomla! Specific Links\",\
}\
}\
]\
}";
//NSLog(@"%@", jsonString);
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
if (jsonDictionary) {
//NSLog(@"%@", jsonDictionary);
NSArray *posts = [jsonDictionary objectForKey:@"posts"];
for (NSDictionary *aPost in posts) {
NSLog(@"%@", aPost);
}
}else {
if (error) {
NSLog(@"Error %@ encountered while creating JSON Dictionary", [error localizedDescription]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment