Implemented parsedBody based on the new RKParserRegistry

This commit is contained in:
Leon
2011-06-15 13:53:05 +02:00
parent 2493828414
commit 2c5700fded
2 changed files with 20 additions and 4 deletions

View File

@@ -83,10 +83,16 @@
*/
- (NSString*)bodyAsString;
/*!
* Return the response body parsed as JSON into an object
* @deprecated in version 2.0
*/
- (id)bodyAsJSON;
/**
* Return the response body parsed as JSON into an object
*/
- (id)bodyAsJSON;
- (id)parsedBody;
/**
* Will determine if there is an error object and use it's localized message

View File

@@ -10,6 +10,7 @@
#import "RKNotifications.h"
#import "RKNetwork.h"
#import "RKLog.h"
#import "RKParserRegistry.h"
// Set Logging Component
#undef RKLogComponent
@@ -143,13 +144,22 @@ extern NSString* cacheURLKey;
return [[[NSString alloc] initWithData:self.body encoding:NSUTF8StringEncoding] autorelease];
}
// TODO: Reimplement as parsedBody
- (id)bodyAsJSON {
[NSException raise:nil format:@"Reimplemented as parsedBody!!!"];
// return [[[[RKJSONParser alloc] init] autorelease] objectFromString:[self bodyAsString]];
[NSException raise:nil format:@"Reimplemented as parsedBody"];
return nil;
}
- (id)parsedBody {
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:[self contentType]];
NSError *error;
id object = [parser objectFromString:[self bodyAsString] error:&error];
if (error == nil) {
// TODO throw parse error?
return nil;
}
return object;
}
- (NSString*)failureErrorDescription {
if ([self isFailure]) {
return [_failureError localizedDescription];