diff options
| author | Ronny Fenrich <Fenrich@Gmail.com> | 2013-06-13 13:40:44 -0600 |
|---|---|---|
| committer | Ronny Fenrich <Fenrich@Gmail.com> | 2013-06-13 13:40:44 -0600 |
| commit | bf6c97cdee2264656211126ee01066c3c5d4bd8d (patch) | |
| tree | df4a6a9ed1b76109a57d1bf71c85b5632a6e3a0b /Volta/Additions/KGJSON/KGJSON.m | |
| parent | d6d01c9dd86561ad2121f0f85f0a4529142d5093 (diff) | |
added Xcode project and converted to CocoaPods (added a bunch of libraries)
Diffstat (limited to 'Volta/Additions/KGJSON/KGJSON.m')
| -rw-r--r-- | Volta/Additions/KGJSON/KGJSON.m | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Volta/Additions/KGJSON/KGJSON.m b/Volta/Additions/KGJSON/KGJSON.m new file mode 100644 index 0000000..e6f2f98 --- /dev/null +++ b/Volta/Additions/KGJSON/KGJSON.m @@ -0,0 +1,61 @@ +// +// NSString+KGJSON.m +// KGJSON +// +// Created by David Keegan on 10/16/12. +// Copyright (c) 2012 David Keegan. All rights reserved. +// + +#import "KGJSON.h" + +@implementation NSString(KGJSON) + +- (id)JSONObject{ + if(self == nil){ + return self; + } + NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding]; + return [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; +} + ++ (NSString *)JSONString:(id)object{ + if(object == nil){ + return nil; + } + NSData *json = [NSJSONSerialization dataWithJSONObject:object options:0 error:nil]; + return [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding]; +} + ++ (NSString *)prettyJSONString:(id)object{ + if(object == nil){ + return nil; + } + NSData *json = [NSJSONSerialization dataWithJSONObject:object options:NSJSONWritingPrettyPrinted error:nil]; + return [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding]; +} + +@end + +@implementation NSDictionary(KGJSON) + +- (NSString *)JSONString{ + return [NSString JSONString:self]; +} + +- (NSString *)prettyJSONString{ + return [NSString prettyJSONString:self]; +} + +@end + +@implementation NSArray(KGJSON) + +- (NSString *)JSONString{ + return [NSString JSONString:self]; +} + +- (NSString *)prettyJSONString{ + return [NSString prettyJSONString:self]; +} + +@end |
