Skip to content

Instantly share code, notes, and snippets.

@romyilano
Created February 14, 2013 02:14
Show Gist options
  • Select an option

  • Save romyilano/4950140 to your computer and use it in GitHub Desktop.

Select an option

Save romyilano/4950140 to your computer and use it in GitHub Desktop.
NSJSONSerialization - this class kicks @$$!
NSError *error;
// turn the responseData into an NSDictionary object
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSArray *latestLoans = json[@"loans"];
NSDictionary *loan = latestLoans[0];
// build an info object out of the dictionary
// this is a new way to write dictionaries as of iOS6
NSDictionary *info = @{
@"who":loan[@"name"];
@"where":loan[@"location"][@"country"];
@"what" : [NSNumber numberWithFloat:outstandingAmount]
};
// convert the object o NSData... json!
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:info
options:kNilOptions error:&error];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment