Rest Kit 0.2o에서 작업 중이며 웹에서 Json 형식의 샘플 URL을 사용하고 있습니다. 응답은 아래와 같습니다. 개체 매핑을 사용하고 있습니다. 나는 아래의 링크를 참조로 사용하고있다. "https://github.com/RestKit/RestKit/wiki/Object-Mapping"나는 링크에서 주어진 것과 거의 같은 응답을 사용하고있다. 다음은 RestKit에서 개체를 매핑하는 동안 오류가 발생합니다. 0.20
{
"geonames": [
{
"fcodeName":"capital of a political entity",
"toponymName":"Mexico City",
"countrycode":"MX",
"fcl":"P",
"fclName":"city, village,...",
"name":"Mexiko-Stadt",
"wikipedia":"en.wikipedia.org/wiki/Mexico_City",
"lng":-99.12766456604,
"fcode":"PPLC",
"geonameId":3530597,
"lat":19.428472427036,
"population":12294193
},
{
"fcodeName":"capital of a political entity",
"toponymName":"Manila",
"countrycode":"PH",
"fcl":"P",
"fclName":"city,village,...",
"name":"Manila",
"wikipedia":"en.wikipedia.org/wiki/Manila",
"lng":120.9822,
"fcode":"PPLC",
"geonameId":1701668,
"lat":14.6042,
"population":10444527
}]
}
코드입니다
RKObjectMapping *newsMapping = [RKObjectMapping mappingForClass:[News class]];
[newsMapping addAttributeMappingsFromDictionary:@{
@"fcodeName": @"fcodeName",
@"toponymName": @"toponymName",
@"countrycode": @"countrycode",
@"fcl": @"fcl",
@"fclName": @"fclName",
@"name":@"name",
@"wikipedia":@"wikipedia",
@"lng":@"lng",
@"fcode":@"fcode",
@"geonameId":@"geonameId",
@"lat":@"lat",
@"population":@"population",
}];
RKResponseDescriptor* responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:newsMapping
pathPattern:nil
keyPath:@"newsMapping"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
NSURL* url = [[NSURL alloc]initWithString:@"http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]];
[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(@"Load collection of Articles: %@", mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
// RKLogError(@"Operation failed with error: %@", error);
NSLog(@"THIS IS TEST %@",error);
}];
[objectRequestOperation start];
"뉴스는"모든 일을 한 후 "GeoNames을"
@interface News : NSObject
@property(nonatomic,copy)NSString* fcodeName;
@property(nonatomic,copy)NSString* toponymName;
@property(nonatomic,copy)NSString* countrycode;
@property(nonatomic,copy)NSString* fcl;
@property(nonatomic,copy)NSString* fclName;
@property(nonatomic,copy)NSString* name;
@property(nonatomic,copy)NSString* wikipedia;
@property(nonatomic,copy)NSString* lng;
@property(nonatomic,copy)NSString* fcode;
@property(nonatomic,copy)NSString* geonameId;
@property(nonatomic,copy)NSString* lat;
@property(nonatomic,copy)NSString* population;
의 I 사용하고 클래스와 키 패스 내가 사용하고입니다 이 오류 아래에 있습니다
2013-05-30 12:06:14.376 TestApp[7140:11603] I restkit.network:RKObjectRequestOperation.m:174 GET 'http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo'
2013-05-30 12:06:15.477 TestApp[7140:12b07] E restkit.network:RKObjectRequestOperation.m:236 Test GET 'http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo' (200 OK/0 objects) [request=1.0969s mapping=0.0000s total=1.1056s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo=0x7675f20 {DetailedErrors=(
), NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: newsMapping
The representation inputted to the mapper was found to contain nested object representations at the following key paths: status
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}
2013-05-30 12:06:15.477 TestApp[7140:14d03] blockk
2013-05-30 12:06:15.478 TestApp[7140:14d03] erorrrrrr next ifr
2013-05-30 12:06:15.478 TestApp[7140:14d03] erorrrrrr next ifjhkr
2013-05-30 12:06:15.478 TestApp[7140:11603] THIS IS TEST Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo=0x7675f20 {DetailedErrors=(
), NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: newsMapping
The representation inputted to the mapper was found to contain nested object representations at the following key paths: status
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}
실제로 오류가 발생하면 마지막 줄에 keyPath가 null로 표시됩니다. 그러나 브라우저에서 나는 위에서 언급 한 응답을 얻고 있습니다.
도와주세요
AppDelegate에 다음 두 줄을 추가 할 수 있을까요? 'RKLogConfigureByName ("RestKit/ObjectMapping", RKLogLevelDebug); 그리고 'RKLogConfigureByName ("RestKit/Network", RKLogLevelDebug);'로그가 조금 더 명확 해지기를 바랍니다. 그 원인에 대해서. –