Explorar el 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 hace 11 años
padre
commit
b4d03fc9e9
Se han modificado 1 ficheros con 3 adiciones y 1 borrados
  1. 3 1
      Classes/Utility/FLEXUtility.m

+ 3 - 1
Classes/Utility/FLEXUtility.m

@@ -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