Skip to content

Commit e26e197

Browse files
committed
Merge pull request marcuswestin#174 from vontio/master
pretty print json
2 parents 5a91bac + 9da6b78 commit e26e197

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

WebViewJavascriptBridge/WebViewJavascriptBridgeBase.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ - (void)_queueMessage:(WVJBMessage*)message {
178178
}
179179

180180
- (void)_dispatchMessage:(WVJBMessage*)message {
181-
NSString *messageJSON = [self _serializeMessage:message];
181+
NSString *messageJSON = [self _serializeMessage:message pretty:NO];
182182
[self _log:@"SEND" json:messageJSON];
183183
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
184184
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
@@ -200,8 +200,8 @@ - (void)_dispatchMessage:(WVJBMessage*)message {
200200
}
201201
}
202202

203-
- (NSString *)_serializeMessage:(id)message {
204-
return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:message options:0 error:nil] encoding:NSUTF8StringEncoding];
203+
- (NSString *)_serializeMessage:(id)message pretty:(BOOL)pretty{
204+
return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:message options:(NSJSONWritingOptions)(pretty ? NSJSONWritingPrettyPrinted : 0) error:nil] encoding:NSUTF8StringEncoding];
205205
}
206206

207207
- (NSArray*)_deserializeMessageJSON:(NSString *)messageJSON {
@@ -211,7 +211,7 @@ - (NSArray*)_deserializeMessageJSON:(NSString *)messageJSON {
211211
- (void)_log:(NSString *)action json:(id)json {
212212
if (!logging) { return; }
213213
if (![json isKindOfClass:[NSString class]]) {
214-
json = [self _serializeMessage:json];
214+
json = [self _serializeMessage:json pretty:YES];
215215
}
216216
if ([json length] > 500) {
217217
NSLog(@"WVJB %@: %@ [...]", action, [json substringToIndex:500]);

0 commit comments

Comments
 (0)