Created
November 20, 2012 16:30
-
-
Save SaschaMoellering/4119040 to your computer and use it in GitHub Desktop.
XMl -> JSON
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
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