Last active
August 29, 2015 14:20
-
-
Save cemalyilmaz/7e0c0c6f35c31247ea48 to your computer and use it in GitHub Desktop.
NSDictionary to JSON String
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
| #import <Foundation/Foundation.h> | |
| @interface NSDictionary (MTJSON) | |
| -(NSString*) mt_jsonString; | |
| @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
| #import "NSDictionary+MTJSON.h" | |
| @implementation NSDictionary (MTJSON) | |
| -(NSString*) mt_jsonString{ | |
| NSError *error; | |
| NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self | |
| options:NSJSONWritingPrettyPrinted | |
| error:&error]; | |
| if (!jsonData) { | |
| NSLog(@"JSON String Error: %@", error.localizedDescription); | |
| return @"{}"; | |
| } else { | |
| return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | |
| } | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment