//
//  NSDictionary-Additions.m
//  JasonDevelop
//
//  Created by Jason Lee on 10/29/14.
//  Copyright (c) jasondevelop. All rights reserved.
//

#import "NSDictionary-Additions.h"

@implementation NSDictionary (Additions)

- (BOOL)hasKey:(NSString *)key {
    BOOL hasKey = NO;
    for (NSString *candidateKey in self.allKeys) {
        if ([key isEqualToString:candidateKey]) {
            hasKey = YES;
            break;
        }
    }
    return hasKey;
}

- (NSString *)jsonStringWithPrettyPrint:(BOOL) prettyPrint {
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
                                                       options:(NSJSONWritingOptions)    (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
                                                         error:&error];

    if (!jsonData) {
        NSLog(@"bv_jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
        return @"{}";
    } else {
        return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
}

@end
