Skip to content

Instantly share code, notes, and snippets.

@maojj
Created July 15, 2013 04:26
Show Gist options
  • Save maojj/5997500 to your computer and use it in GitHub Desktop.
Save maojj/5997500 to your computer and use it in GitHub Desktop.
系统json解析
#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