Estás en: Ayuda con Restkit
Para dar las gracias debes entrar o registrarte en el foro
Estimados,
Soy bastante nuevo en objective-c. Los tutoriales que he leido aca me han servido muchísimo, pero en programación mas avanzada tengo un problema que no he podido solucionar.
Tengo que obtener los datos de un webservice que devuelve el siguiente XML por metodo GET
Tengo el siguiente codigo en objective-c con Restkit 0.20.0
[RKMIMETypeSerialization registerClass:[RKURLEncodedSerialization class] forMIMEType:@"text/xml"];
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[MyClass class]];
[objectMapping addAttributeMappingsFromDictionary:@{ @"valor1": @"valor1", @"valor2": @"valor2", @"valor3": @"valor3" }];
// Set up the response descriptor
RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor
responseDescriptorWithMapping:objectMapping
pathPattern:nil
keyPath:@"Piece"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
NSMutableString *Link = [NSMutableString stringWithString:@"http://url?Parametro="];
[Link appendString:parametro.text];
NSURL *URL = [NSURL URLWithString:Link];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc]
initWithRequest:request responseDescriptors:@[responseDescriptor]];
[operation setCompletionBlockWithSuccess:
^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSArray *myArray = result.array;
for (MyClass *p in myArray) {
NSLog(@"Name: %@", p.valor1);
}
} failure:^(RKObjectRequestOperation *operation, NSError *error)
{
RKLogError(@"Operation failed with error: %@", error);
}]; [operation start];
Operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo=0x86654a0 {DetailedErrors=(
), NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: Piece
The representation inputted to the mapper was found to contain nested object representations at the following key paths: 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}
lauchon escribió:Estimados,
Soy bastante nuevo en objective-c. Los tutoriales que he leido aca me han servido muchísimo, pero en programación mas avanzada tengo un problema que no he podido solucionar.
Tengo que obtener los datos de un webservice que devuelve el siguiente XML por metodo GETstring string string
Tengo el siguiente codigo en objective-c con Restkit 0.20.0
- Código: Seleccionar todo
[RKMIMETypeSerialization registerClass:[RKURLEncodedSerialization class] forMIMEType:@"text/xml"];
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[MyClass class]];
[objectMapping addAttributeMappingsFromDictionary:@{ @"valor1": @"valor1", @"valor2": @"valor2", @"valor3": @"valor3" }];
// Set up the response descriptor
RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor
responseDescriptorWithMapping:objectMapping
pathPattern:nil
keyPath:@"Piece"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
NSMutableString *Link = [NSMutableString stringWithString:@"http://url?Parametro="];
[Link appendString:parametro.text];
NSURL *URL = [NSURL URLWithString:Link];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc]
initWithRequest:request responseDescriptors:@[responseDescriptor]];
[operation setCompletionBlockWithSuccess:
^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSArray *myArray = result.array;
for (MyClass *p in myArray) {
NSLog(@"Name: %@", p.valor1);
}
} failure:^(RKObjectRequestOperation *operation, NSError *error)
{
RKLogError(@"Operation failed with error: %@", error);
}]; [operation start];
Y al ejecutarlo recibo el siguiente mensaje en el OutputOperation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo=0x86654a0 {DetailedErrors=(
), NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: Piece
The representation inputted to the mapper was found to contain nested object representations at the following key paths: 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}
No entiendo por que dice que el KeyPath esta mal si la estructura del XML comienza con el nodo Piece y dentro de el los datos.
Saludos.
Gracias.