Created
September 15, 2014 21:23
-
-
Save gustafnilklint/2e005ff9f6001147c78d to your computer and use it in GitHub Desktop.
NSDictionary print itself as litheral
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSDictionary+prettyPrint.m | |
// GarageRemote | |
// | |
// Created by Gustaf Nilklint on 2014-09-15. | |
// Copyright (c) 2014 Gustaf Nilklint. All rights reserved. | |
// | |
#import "NSDictionary+prettyPrint.h" | |
@implementation NSDictionary (prettyPrint) | |
- (NSString*)myDescription; | |
{ | |
NSError *error; | |
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self | |
options:NSJSONWritingPrettyPrinted | |
error:&error]; | |
if (error) NSLog(@"Error: %@", error); | |
NSString *jsonString = [[NSString alloc] initWithData:jsonData | |
encoding:NSUTF8StringEncoding]; | |
NSString *litheralsString = [jsonString stringByReplacingOccurrencesOfString:@"{" withString:@"@{"]; | |
litheralsString = [litheralsString stringByReplacingOccurrencesOfString:@"[" withString:@"@["]; | |
litheralsString = [litheralsString stringByReplacingOccurrencesOfString:@" \"" withString:@"@\""]; | |
return litheralsString; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment