Created
February 14, 2013 02:14
-
-
Save romyilano/4950140 to your computer and use it in GitHub Desktop.
NSJSONSerialization - this class kicks @$$!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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