Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save minyoad/6d50918a507e2a6bce3cb0c2943d5ab0 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