Last active
August 29, 2015 14:05
-
-
Save dezinezync/acded4c2cf09f175469e to your computer and use it in GitHub Desktop.
DZJSON
This file contains hidden or 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+JSON.h | |
| // DiamConnect | |
| // | |
| // Created by Nikhil Nigade on 8/13/14. | |
| // Copyright (c) 2014 agilepc-107. All rights reserved. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface NSString (JSON) | |
| - (id)dz_parse; | |
| @end | |
| @interface NSMutableString (JSON) | |
| - (id)dz_parse; | |
| @end | |
| @interface NSDictionary (JSON) | |
| - (NSString *)dz_stringify; | |
| @end | |
| @interface NSMutableDictionary (JSON) | |
| - (NSString *)dz_stringify; | |
| @end |
This file contains hidden or 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+JSON.m | |
| // DiamConnect | |
| // | |
| // Created by Nikhil Nigade on 8/13/14. | |
| // Copyright (c) 2014 agilepc-107. All rights reserved. | |
| // | |
| #import "DZJSON.h" | |
| @implementation NSString (JSON) | |
| - (id)dz_parse | |
| { | |
| NSError *jsonError; | |
| id obj = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&jsonError]; | |
| if(jsonError) | |
| { | |
| LogID(jsonError); | |
| return nil; | |
| } | |
| return obj; | |
| } | |
| @end | |
| @implementation NSMutableString (JSON) | |
| - (id)dz_parse | |
| { | |
| NSError *jsonError; | |
| id obj = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&jsonError]; | |
| if(jsonError) | |
| { | |
| LogID(jsonError); | |
| return nil; | |
| } | |
| return obj; | |
| } | |
| @end | |
| @implementation NSDictionary (JSON) | |
| - (NSString *)dz_stringify | |
| { | |
| NSError *jsonError; | |
| NSData *data = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&jsonError]; | |
| if(jsonError) | |
| { | |
| LogID(jsonError); | |
| return nil; | |
| } | |
| if(!data || !sizeof([data bytes])) | |
| { | |
| return nil; | |
| } | |
| return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; | |
| } | |
| @end | |
| @implementation NSMutableDictionary (JSON) | |
| - (NSString *)dz_stringify | |
| { | |
| NSError *jsonError; | |
| NSData *data = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&jsonError]; | |
| if(jsonError) | |
| { | |
| LogID(jsonError); | |
| return nil; | |
| } | |
| if(!data || !sizeof([data bytes])) | |
| { | |
| return nil; | |
| } | |
| return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment