Skip to content

Instantly share code, notes, and snippets.

@SaschaMoellering
Created November 20, 2012 16:30
Show Gist options
  • Save SaschaMoellering/4119040 to your computer and use it in GitHub Desktop.
Save SaschaMoellering/4119040 to your computer and use it in GitHub Desktop.
XMl -> JSON
XML -> NSDictionary
NSError *error = nil;
NSString *contents = [NSString stringWithContentsOfURL:[NSURL URLWithString:searchIncentivesURL]
encoding:NSUTF8StringEncoding
error:&error];
NSData* xmlData = [contents dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLData:xmlData error:error];
NSDictionary -> JSON
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:xmlDictionary
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment