Skip to content

Commit

Permalink
pretty print json
Browse files Browse the repository at this point in the history
add pretty param to _serializeMessage
  • Loading branch information
vontio committed Dec 25, 2015
1 parent 5a91bac commit 9da6b78
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions WebViewJavascriptBridge/WebViewJavascriptBridgeBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ - (void)_queueMessage:(WVJBMessage*)message {
}

- (void)_dispatchMessage:(WVJBMessage*)message {
NSString *messageJSON = [self _serializeMessage:message];
NSString *messageJSON = [self _serializeMessage:message pretty:NO];
[self _log:@"SEND" json:messageJSON];
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
Expand All @@ -200,8 +200,8 @@ - (void)_dispatchMessage:(WVJBMessage*)message {
}
}

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

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

0 comments on commit 9da6b78

Please sign in to comment.