下图是我回来的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对象的数组吗?它似乎返回&#34;描述&#34;的价值。在数组中没有&#34;引用&#34;值。我究竟做错了什么?
返回JSON:
答案 0 :(得分:2)
description
是一个已定义的方法名称,因此通过添加您自己的同名属性,您将覆盖默认实现。所以,你确实拥有了你期望的对象,但是日志会打印出你不期望的东西。
更改您的媒体资源的名称,使其与description
不重叠。