Files
eqn.ios/Sources/Earthquake Network/Libs/NSDictionary+BVJSONString.m
T
2020-07-24 16:21:21 +02:00

26 lines
827 B
Objective-C

//
// NSDictionary+BVJSONString.m
// Smash
//
// Created by Luca Beretta on 24/03/2019.
// Copyright © 2019 Luca Beretta. All rights reserved.
//
#import "NSDictionary+BVJSONString.h"
@implementation NSDictionary (BVJSONString)
-(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
options:(NSJSONWritingOptions) (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
error:&error];
if (! jsonData) {
NSLog(@"%s: error: %@", __func__, error.localizedDescription);
return @"{}";
} else {
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
}
@end