Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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