Adding shortcircuit for _AFNETWORKING_PREFER_NSJSONSERIALIZATION_
This commit is contained in:
parent
54194a3cb6
commit
aaa5858546
1 changed files with 41 additions and 24 deletions
|
|
@ -32,6 +32,12 @@ static NSData * AFJSONEncode(id object, NSError **error) {
|
|||
id _NSJSONSerializationClass = NSClassFromString(@"NSJSONSerialization");
|
||||
SEL _NSJSONSerializationSelector = NSSelectorFromString(@"dataWithJSONObject:options:error:");
|
||||
|
||||
#ifdef _AFNETWORKING_PREFER_NSJSONSERIALIZATION_
|
||||
if (_NSJSONSerializationClass && [_NSJSONSerializationClass respondsToSelector:_NSJSONSerializationSelector]) {
|
||||
goto _af_nsjson_encode;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_JSONKitSelector && [object respondsToSelector:_JSONKitSelector]) {
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[object methodSignatureForSelector:_JSONKitSelector]];
|
||||
invocation.target = object;
|
||||
|
|
@ -69,6 +75,7 @@ static NSData * AFJSONEncode(id object, NSError **error) {
|
|||
*error = [[[NSError alloc] initWithDomain:NSStringFromClass([exception class]) code:0 userInfo:[exception userInfo]] autorelease];
|
||||
}
|
||||
} else if (_NSJSONSerializationClass && [_NSJSONSerializationClass respondsToSelector:_NSJSONSerializationSelector]) {
|
||||
_af_nsjson_encode: {
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[_NSJSONSerializationClass methodSignatureForSelector:_NSJSONSerializationSelector]];
|
||||
invocation.target = _NSJSONSerializationClass;
|
||||
invocation.selector = _NSJSONSerializationSelector;
|
||||
|
|
@ -80,6 +87,7 @@ static NSData * AFJSONEncode(id object, NSError **error) {
|
|||
|
||||
[invocation invoke];
|
||||
[invocation getReturnValue:&data];
|
||||
}
|
||||
} else {
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedString(@"Please either target a platform that supports NSJSONSerialization or add one of the following libraries to your project: JSONKit, SBJSON, or YAJL", nil) forKey:NSLocalizedRecoverySuggestionErrorKey];
|
||||
[[NSException exceptionWithName:NSInternalInconsistencyException reason:NSLocalizedString(@"No JSON generation functionality available", nil) userInfo:userInfo] raise];
|
||||
|
|
@ -98,6 +106,13 @@ static id AFJSONDecode(NSData *data, NSError **error) {
|
|||
id _NSJSONSerializationClass = NSClassFromString(@"NSJSONSerialization");
|
||||
SEL _NSJSONSerializationSelector = NSSelectorFromString(@"JSONObjectWithData:options:error:");
|
||||
|
||||
|
||||
#ifdef _AFNETWORKING_PREFER_NSJSONSERIALIZATION_
|
||||
if (_NSJSONSerializationClass && [_NSJSONSerializationClass respondsToSelector:_NSJSONSerializationSelector]) {
|
||||
goto _af_nsjson_decode;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_JSONKitSelector && [data respondsToSelector:_JSONKitSelector]) {
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[data methodSignatureForSelector:_JSONKitSelector]];
|
||||
invocation.target = data;
|
||||
|
|
@ -130,6 +145,7 @@ static id AFJSONDecode(NSData *data, NSError **error) {
|
|||
[invocation invoke];
|
||||
[invocation getReturnValue:&JSON];
|
||||
} else if (_NSJSONSerializationClass && [_NSJSONSerializationClass respondsToSelector:_NSJSONSerializationSelector]) {
|
||||
_af_nsjson_decode: {
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[_NSJSONSerializationClass methodSignatureForSelector:_NSJSONSerializationSelector]];
|
||||
invocation.target = _NSJSONSerializationClass;
|
||||
invocation.selector = _NSJSONSerializationSelector;
|
||||
|
|
@ -141,6 +157,7 @@ static id AFJSONDecode(NSData *data, NSError **error) {
|
|||
|
||||
[invocation invoke];
|
||||
[invocation getReturnValue:&JSON];
|
||||
}
|
||||
} else {
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedString(@"Please either target a platform that supports NSJSONSerialization or add one of the following libraries to your project: JSONKit, SBJSON, or YAJL", nil) forKey:NSLocalizedRecoverySuggestionErrorKey];
|
||||
[[NSException exceptionWithName:NSInternalInconsistencyException reason:NSLocalizedString(@"No JSON parsing functionality available", nil) userInfo:userInfo] raise];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue