Created
December 9, 2012 23:28
-
-
Save loretoparisi/4247490 to your computer and use it in GitHub Desktop.
Objective-C Unicode Escaping + JSON
This file contains hidden or 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
/** | |
* 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