Skip to content

Instantly share code, notes, and snippets.

@pratikshabhisikar
Created December 10, 2011 11:48
Show Gist options
  • Save pratikshabhisikar/1454978 to your computer and use it in GitHub Desktop.
Save pratikshabhisikar/1454978 to your computer and use it in GitHub Desktop.
#define SNAKE_AND_LADDER_DATA @"{\"data\":{\"1\":{\"snake\":[{\"from\":\"95\", \"to\":\"10\"}, {\"from\":\"75\", \"to\":\"20\"}], \"ladder\":[{\"from\":\"15\", \"to\":\"50\"}, {\"from\":\"25\", \"to\":\"90\"}]},\
\"2\":{\"snake\":[{\"from\":\"95\", \"to\":\"10\"}, {\"from\":\"75\", \"to\":\"20\"}], \"ladder\":[{\"from\":\"15\", \"to\":\"50\"}, {\"from\":\"25\", \"to\":\"90\"}]}\
}\
}"
NSData *snakeLadderData = [SNAKE_AND_LADDER_DATA dataUsingEncoding:NSASCIIStringEncoding];
NSDictionary *rootDictionary = [NSJSONSerialization JSONObjectWithData:snakeLadderData options:NSJSONWritingPrettyPrinted error:nil];
NSLog(@"Dictionary: %@", rootDictionary);
NSDictionary *snakeLadderDictionary = [rootDictionary objectForKey:@"data"];
NSLog(@"Info: %@", snakeLadderDictionary);
NSDictionary *firstTheme = [snakeLadderDictionary objectForKey:@"1"];
NSDictionary *secondTheme = [snakeLadderDictionary objectForKey:@"2"];
NSLog(@"First Theme: %@", firstTheme);
NSLog(@"Second Theme: %@", secondTheme);
NSArray *firstThemeSnakes = [firstTheme objectForKey:@"snake"];
for (NSDictionary *aSnake in firstThemeSnakes) {
NSLog(@"Snake From: %d", [[aSnake objectForKey:@"from"] integerValue]);
NSLog(@"Snake To: %d", [[aSnake objectForKey:@"to"] integerValue]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment