Created
January 10, 2013 10:04
-
-
Save matths/4500902 to your computer and use it in GitHub Desktop.
some basics using NSJSONSerialization (iOS5 and up.)
This file contains 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
NSString *strArrayExample = @"%5B%22hello%22%2C%22world!%22%2C12%5D"; | |
NSString *strObjectExample = @"%7B%22a%22%3A%221%22%2C%22b%22%3A%22c%22%7D"; | |
NSString *str = [strArrayExample stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
NSLog(@"str:: %@", str); | |
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding]; | |
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; | |
NSLog(@"type of data:: %@", NSStringFromClass([json class])); | |
if ([json isKindOfClass:[NSArray class]]) { | |
NSLog(@"is array"); | |
} else if ([json isKindOfClass:[NSDictionary class]]) { | |
NSLog(@"is object"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment