diff --git a/sample/Hackbook/Hackbook/RootViewController.m b/sample/Hackbook/Hackbook/RootViewController.m index 13ed4e5237..5583793760 100644 --- a/sample/Hackbook/Hackbook/RootViewController.m +++ b/sample/Hackbook/Hackbook/RootViewController.m @@ -373,8 +373,9 @@ - (void)fbSessionInvalidated { #pragma mark - FBRequestDelegate Methods /** - * Called when the Facebook API request has returned a response. This callback - * gives you access to the raw response. It's called before + * Called when the Facebook API request has returned a response. + * + * This callback gives you access to the raw response. It's called before * (void)request:(FBRequest *)request didLoad:(id)result, * which is passed the parsed response object. */ @@ -384,9 +385,11 @@ - (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)respons /** * Called when a request returns and its response has been parsed into - * an object. The resulting object may be a dictionary, an array, a string, - * or a number, depending on the format of the API response. If you need access - * to the raw response, use: + * an object. + * + * The resulting object may be a dictionary, an array or a string, depending + * on the format of the API response. If you need access to the raw response, + * use: * * (void)request:(FBRequest *)request * didReceiveResponse:(NSURLResponse *)response diff --git a/src/FBRequest.h b/src/FBRequest.h index f9fb0edf76..7c6ee5eda8 100644 --- a/src/FBRequest.h +++ b/src/FBRequest.h @@ -105,7 +105,11 @@ typedef NSUInteger FBRequestState; - (void)requestLoading:(FBRequest *)request; /** - * Called when the server responds and begins to send back data. + * Called when the Facebook API request has returned a response. + * + * This callback gives you access to the raw response. It's called before + * (void)request:(FBRequest *)request didLoad:(id)result, + * which is passed the parsed response object. */ - (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response; @@ -118,8 +122,12 @@ typedef NSUInteger FBRequestState; * Called when a request returns and its response has been parsed into * an object. * - * The resulting object may be a dictionary, an array, a string, or a number, - * depending on thee format of the API response. + * The resulting object may be a dictionary, an array or a string, depending + * on the format of the API response. If you need access to the raw response, + * use: + * + * (void)request:(FBRequest *)request + * didReceiveResponse:(NSURLResponse *)response */ - (void)request:(FBRequest *)request didLoad:(id)result; diff --git a/src/FBRequest.m b/src/FBRequest.m index f12b89513d..dab988b0ba 100644 --- a/src/FBRequest.m +++ b/src/FBRequest.m @@ -189,7 +189,6 @@ - (id)parseJsonResponse:(NSData *)data error:(NSError **)error { NSString* responseString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; - SBJSON *jsonParser = [[SBJSON new] autorelease]; if ([responseString isEqualToString:@"true"]) { return [NSDictionary dictionaryWithObject:@"true" forKey:@"result"]; } else if ([responseString isEqualToString:@"false"]) { @@ -203,9 +202,15 @@ - (id)parseJsonResponse:(NSData *)data error:(NSError **)error { } + SBJSON *jsonParser = [[SBJSON alloc] init]; id result = [jsonParser objectWithString:responseString]; - - if (![result isKindOfClass:[NSArray class]]) { + [jsonParser release]; + + if (result == nil) { + return responseString; + } + + if ([result isKindOfClass:[NSDictionary class]]) { if ([result objectForKey:@"error"] != nil) { if (error != nil) { *error = [self formError:kGeneralErrorCode @@ -272,7 +277,7 @@ - (void)handleResponseData:(NSData *)data { [self failWithError:error]; } else if ([_delegate respondsToSelector: @selector(request:didLoad:)]) { - [_delegate request:self didLoad:(result == nil ? data : result)]; + [_delegate request:self didLoad:result]; } }