【发布时间】:2014-03-22 19:51:11
【问题描述】:
下图中是我返回的 JSON。
下面是我的代码映射:
+(RKMapping *)googleMapping
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[mappingModel class]];
[mapping addAttributeMappingsFromDictionary:@{
@"description" : @"description",
@"reference" : @"reference"
}];
return mapping;
}
获取:
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping
method:RKRequestMethodGET
pathPattern:nil
keyPath:@"predictions" statusCodes:statusCodeSet];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request
responseDescriptors:@[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"mappingResults %@", mappingResult);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"mappingResults Error %@", error);
}];
[operation start];
NSLog:
2014-03-22 12:42:03.988 Google+RESTKit[21229:60b] I restkit.network:RKObjectRequestOperation.m:180 GET 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=cofee&sensor=true&key=1234&location=0.000000,0.000000&radius=100.000000'
2014-03-22 12:42:04.031 Google+RESTKit[21229:6a03] I restkit.network:RKObjectRequestOperation.m:250 GET 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=cofee&sensor=true&key=1234&location=0.000000,0.000000&radius=100.000000' (200 OK / 5 objects) [request=0.0430s mapping=0.0007s total=0.0474s]
2014-03-22 12:42:04.032 Google+RESTKit[21229:60b] mappingResults <RKMappingResult: 0x1733ecf0, results={
predictions = (
"Coffee Road, Modesto, CA, United States",
"Coffee Bay, Eastern Cape, South Africa",
"Coffee Road, Bakersfield, CA, United States",
"Coffeeville, MS, United States",
"Coffeen, IL, United States"
);
}>
返回的mappingResult应该是一个带有NSDictionary Objects的数组吧?它似乎在数组中返回“描述”的值,并且没有“参考”值。我究竟做错了什么?
返回的 JSON:
【问题讨论】:
标签: objective-c json restkit restkit-0.20