【发布时间】:2014-07-09 13:22:24
【问题描述】:
我在 IOS 上使用 restkit。我无法解析一个简单的 json 对象。
我返回了一个简单的 json 对象:
{"_id"=>"537c235189d50fabcc000009",
"about"=>"nice",
"headline"=>"looking",
"access_token"=>
"$2a$10$oZ4IiaVBxHhc1qGeBoZv1uYonBM3Qb5Y010rTkUOynDZIGdGagqJy"}
我的设置:
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureRestKit];
[self loadVenues];
}
- (void)loadVenues
{
NSString *clientToken = SNAPTOKEN;
NSDictionary *profile = @{@"os": @"iOS",
@"device_token": @"first_token",
@"password":@"password",
@"email":@"email",
@"headline":@"hello world"};
NSDictionary *queryParams = @{@"token" : clientToken,
@"profile" : profile};
[[RKObjectManager sharedManager] postObject: nil
path: @"/profiles/new"
parameters:queryParams
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"log%@", mappingResult );
_profile = mappingResult.array;
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"What do you mean by 'there is no coffee?': %@", error);
}];
}
- (void)configureRestKit
{
// initialize AFNetworking HTTPClient
NSURL *baseURL = [NSURL URLWithString:@"https://airimg.com"];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
// initialize RestKit
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
// setup object mappings
RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Profile class]];
[venueMapping addAttributeMappingsFromDictionary:@{ @"_id": @"about", @"access_token": @"headline" }];
// register mappings with the provider using a response descriptor
RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:venueMapping
method:RKRequestMethodPOST
pathPattern:@"/profiles/new"
keyPath:@"response"
statusCodes:[NSIndexSet indexSetWithIndex:200]];
[objectManager addResponseDescriptor:responseDescriptor];
}
我有以下错误:
NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: response
The representation inputted to the mapper was found to contain nested object representations at the following key paths: _id, about, access_token, headline
This likely indicates that you have misconfigured the key paths for your mappings., NSLocalizedDescription=No mappable object representations were found at the key paths searched., keyPath=null}
【问题讨论】:
标签: ios parsing mapping restkit