Explorar o código

Unescape forward slashes when making pretty JSON.

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.
Ryan Olson %!s(int64=11) %!d(string=hai) anos
pai
achega
b4d03fc9e9
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      Classes/Utility/FLEXUtility.m

+ 3 - 1
Classes/Utility/FLEXUtility.m

@@ -257,7 +257,9 @@
 + (NSString *)prettyJSONStringFromData:(NSData *)data
 + (NSString *)prettyJSONStringFromData:(NSData *)data
 {
 {
     id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
     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
 @end