Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
Created December 9, 2012 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save loretoparisi/4247490 to your computer and use it in GitHub Desktop.
Save loretoparisi/4247490 to your computer and use it in GitHub Desktop.
Objective-C Unicode Escaping + JSON
/**
* LP: Escape Unicode for json string object
*/
-(NSString*)escapeUnicodeWithString:(NSString*)stringToEscape {
NSError *error;
NSString *escapedString;
escapedString = [stringToEscape JSONStringWithOptions:JKSerializeOptionEscapeUnicode includeQuotes:YES error:&error];
if(error) {
return stringToEscape;
}
return [(NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)escapedString,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8 ) autorelease];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment