Created
July 15, 2013 04:26
-
-
Save maojj/5997500 to your computer and use it in GitHub Desktop.
系统json解析
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
#import <Foundation/Foundation.h> | |
@interface NSString (JSON) | |
- (id) JSONValue; | |
@end | |
@implementation NSString (JSON) | |
- (id) JSONValue { | |
NSError *error = nil; | |
id obj = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&error]; | |
if (error) | |
NSLog(@"%@", [error description]); | |
return obj; | |
} | |
@end | |
@interface NSData (JSON) | |
- (id) JSONValue; | |
@end | |
@implementation NSData (JSON) | |
- (id) JSONValue { | |
NSError *error = nil; | |
id obj = [NSJSONSerialization JSONObjectWithData:self options:NSJSONReadingMutableContainers error:&error]; | |
if (error) | |
NSLog(@"%@", [error description]); | |
return obj; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment