Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Escape NSString so that it can be passed to webview
- (NSString *)stringByEscapingJSONReservedCharacters {
return [[[[[[[[self stringByReplacingOccurrencesOfString:@"\\\\" withString:@"☃"] /* \\ (single slash character) for snowman */
stringByReplacingOccurrencesOfString:@"\\n" withString:@"\\\\n"] /* \n for \\n */
stringByReplacingOccurrencesOfString:@"\\t" withString:@"\\\\t"] /* \t for \\t */
stringByReplacingOccurrencesOfString:@"\\b" withString:@"\\\\b"] /* \b for \\b */
stringByReplacingOccurrencesOfString:@"\\f" withString:@"\\\\f"] /* \f for \\f */
stringByReplacingOccurrencesOfString:@"\\r" withString:@"\\\\r"] /* \r for \\r */
stringByReplacingOccurrencesOfString:@"\\\"" withString:@"\\\\\""] /* \" for \\" */
stringByReplacingOccurrencesOfString:@"☃" withString:@"\\\\\\\\"]; /* snowman for \\\\ (single slash character) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.