NSArray-Addtions.m 805 B

12345678910111213141516171819202122232425262728
  1. //
  2. // NSArray-Addtions.m
  3. // JasonDevelop
  4. //
  5. // Created by Jason Lee on 10/29/14.
  6. // Copyright (c) jasondevelop. All rights reserved.
  7. //
  8. #import "NSArray-Addtions.h"
  9. @implementation NSArray (Addtions)
  10. -(NSString*) jsonStringWithPrettyPrint:(BOOL) prettyPrint {
  11. NSError *error;
  12. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
  13. options:(NSJSONWritingOptions) (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
  14. error:&error];
  15. if (!jsonData) {
  16. NSLog(@"bv_jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
  17. return @"[]";
  18. } else {
  19. return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  20. }
  21. }
  22. @end