mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Implemented parsedBody based on the new RKParserRegistry
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user