Created
July 17, 2012 23:19
-
-
Save eoghain/3132791 to your computer and use it in GitHub Desktop.
NSJSONSerilization compatibility using SBJSON (json-framework) for < iOS5 compatibility kinda
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 "SBJson.h" | |
#import <Foundation/Foundation.h> | |
#import <objc/runtime.h> | |
@interface MYJSONSerialization : NSObject | |
+ (NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error; | |
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error; | |
@end | |
@implementation MYJSONSerialization | |
+ (void)load | |
{ | |
if (!NSClassFromString(@"NSJSONSerialization")) | |
{ | |
Class mySubclass = objc_allocateClassPair([MYJSONSerialization class], "NSJSONSerialization", 0); | |
objc_registerClassPair(mySubclass); | |
} | |
} | |
+ (NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error | |
{ | |
// This seems redundant (turn obj into string, then string into data)? | |
return [[obj JSONRepresentation] dataUsingEncoding:NSUTF8StringEncoding]; | |
} | |
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error | |
{ | |
return [data JSONValue]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment