NSJSONSerialization escapes these but forward slashes are valid in JSON. When we display the JSON in a web view, it is helpful to have URLs without the escaping to make the web view’s URL data detector work.
@@ -257,7 +257,9 @@
+ (NSString *)prettyJSONStringFromData:(NSData *)data
{
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
- return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:NULL] encoding:NSUTF8StringEncoding];
+ NSString *jsonString = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:NULL] encoding:NSUTF8StringEncoding];
+ // NSJSONSerialization escapes forward slashes. We want pretty json, so run through and unescape the slashes.
+ return [jsonString stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
}
@end